簡體   English   中英

戰爭,ejb-jar和persistence.xml

[英]war, ejb-jar and persistence.xml

我有兩個位於[WAR] / WEB-INF / lib中的ejb-jars項目。 這兩個ejb-jars都使用JPA並包含帶注釋的@Entity類。 但是我在打包和部署方面遇到了問題(Glassfish 4)。 如果我的兩個罐子都包含persistence.xml,則在delpoyment上會出現以下異常

java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [...] in the scope of the module called [...]. Please verify your application.

我將persistence.xml放在WAR / META-INF中,並從ejb-jars中刪除persistence.xml 部署成功,但是運行時出現異常

java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: Exception Description: Problem compiling [SELECT ...]. [14, 18] The abstract schema type 'MyClass' is unknown.

MyClass是來自ejb-jar之一的@Entity類。 我認為問題在於此ejb-jar中缺少persistence.xml

最后,我嘗試將persistence.xml放在WAR和ejb-jars中,但是我又得到了

java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [...] in the scope of the module called [...]. Please verify your application.

放置persistence.xml的適當位置是什么,打包此類應用程序的適當方法是什么?

嘗試將所有實體從ejb項目和persistence.xml都提取到簡單的jar文件中,然后將該jar文件放到WEB-INF / lib中(我沒有使用該配置,因此它可能無法正常工作,確保可以正常工作如果是EAR包裝,則表示EAR,在ear / lib文件夾中有3個模塊,Web和2個ejbs和實體jar。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM