Wildfly 8.2 无法扫描 WEB-INF/lib/*.jar 目录中的实体。这是预期的行为吗?
Wildfly 8.2 fails scanning entities inside WEB-INF/lib/*.jar directory. Is this the expected behavior?
我正在部署一个 war,其中包含 WEB-INF/classes
目录中的实体,但现在我将这些实体移到了一个单独的 proyect/module 中,现在这些实体驻留在 [=14] 中=]
更改后,wildfly 无法在部署时扫描产生错误的实体。
然后我尝试添加
<class>class.inside.webinf.lib.Entity1</class>
我的 persistence.xml 文件中的标签以及正确部署的所有内容。
完整 persistence.xml
在 file.war/WEB-INF/classes/META-INF/persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="pu" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/jboss/datasources/sgsdscore</jta-data-source>
<class>io.ingenia.sgsds.score.entity.Entity1</class>
<class>io.ingenia.sgsds.score.entity.EntityN</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.jdbc.batch_size" value="200"/>
<property name="hibernate.order_inserts" value="true" />
<property name="hibernate.order_updates" value="true" />
<property name="hibernate.cache.use_second_level_cache" value="true"/>
</properties>
</persistence-unit>
</persistence>
我是不是漏掉了什么?
WEB-INF/lib/*.jar
中的 EJB,但已成功扫描...
一般来说,这应该可行。我在我的大多数项目中使用 WEB-INF/lib/*.jar
中的 JPA 实体 类。
但是,当您的某些 类 与 persistence.xml
描述符不在同一个 JAR 中时,可能会出现问题。
如果没有看到您的 persistence.xml
文件,很难说。您可以指定 exclude-unlisted-classes
,这将表示只查看列出的 类。您必须使用 jar-file
来指示要扫描的 JAR 文件(如果您已经这样做,从您的问题中不清楚。
我想这个答案也回答了我的问题
像 WEB-INF/lib/entities.jar
这样的 lib 目录中的实体很好,但是 persistence.xml 文件必须在 WEB-INF/lib/entities.jar/META-INF/persistence.xml
中
如果 persistence.xml 文件在 WEB-INF/classes/META-INF/persistence.xml
内,那么自动扫描只会在 WEB-INF/classes/*
内发生
有道理。 (有点……)
我正在部署一个 war,其中包含 WEB-INF/classes
目录中的实体,但现在我将这些实体移到了一个单独的 proyect/module 中,现在这些实体驻留在 [=14] 中=]
更改后,wildfly 无法在部署时扫描产生错误的实体。
然后我尝试添加
<class>class.inside.webinf.lib.Entity1</class>
我的 persistence.xml 文件中的标签以及正确部署的所有内容。
完整 persistence.xml
在 file.war/WEB-INF/classes/META-INF/persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="pu" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/jboss/datasources/sgsdscore</jta-data-source>
<class>io.ingenia.sgsds.score.entity.Entity1</class>
<class>io.ingenia.sgsds.score.entity.EntityN</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.jdbc.batch_size" value="200"/>
<property name="hibernate.order_inserts" value="true" />
<property name="hibernate.order_updates" value="true" />
<property name="hibernate.cache.use_second_level_cache" value="true"/>
</properties>
</persistence-unit>
</persistence>
我是不是漏掉了什么?
WEB-INF/lib/*.jar
中的 EJB,但已成功扫描...
一般来说,这应该可行。我在我的大多数项目中使用 WEB-INF/lib/*.jar
中的 JPA 实体 类。
但是,当您的某些 类 与 persistence.xml
描述符不在同一个 JAR 中时,可能会出现问题。
如果没有看到您的 persistence.xml
文件,很难说。您可以指定 exclude-unlisted-classes
,这将表示只查看列出的 类。您必须使用 jar-file
来指示要扫描的 JAR 文件(如果您已经这样做,从您的问题中不清楚。
我想这个答案也回答了我的问题
像 WEB-INF/lib/entities.jar
这样的 lib 目录中的实体很好,但是 persistence.xml 文件必须在 WEB-INF/lib/entities.jar/META-INF/persistence.xml
如果 persistence.xml 文件在 WEB-INF/classes/META-INF/persistence.xml
内,那么自动扫描只会在 WEB-INF/classes/*
有道理。 (有点……)