使用<jar-file> </jar-file>在JPA persistence.xml中引用JAR文件时出错

时间:2014-10-29 10:50:56

标签: java hibernate jpa

我们有一个由多个JAR组成的Java EE项目,其中几个包含实体。该应用程序打包为具有以下结构的EAR:

app.ear
    lib/core.jar (containing META-INF/persistence.xml)
    lib/module1.jar (contains entities)
    lib/module2.jar (contains entities)
    ...

在persistence.xml中,我们尝试引用包含如下实体的JAR文件:

<persistence ...>
  <persistence-unit name="someName">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

    <jar-file>module1.jar</jar-file>
    <jar-file>module2.jar</jar-file>

    ...
  </persistence-unit>
</persistence>

我看一下JPA 2.1 spec(也在this SO answer中引用),我的配置应该是正确的,对吧?我们的设置对应于JPA规范8.2.1.6.3中的示例2。但是,当我部署应用程序时,我收到此错误消息:

java.lang.IllegalArgumentException: File [module1.jar] referenced by given URL [file:module1.jar] does not exist
    at org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory.buildArchiveDescriptor(StandardArchiveDescriptorFactory.java:73)
    at org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory.buildArchiveDescriptor(StandardArchiveDescriptorFactory.java:48)
    at org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl.buildArchiveDescriptor(AbstractScannerImpl.java:95)
    at org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:63)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.scan(EntityManagerFactoryBuilderImpl.java:723)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:219)
    at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:51)
    at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:182)
    at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:131)
    at org.hibernate.ejb.HibernatePersistence.getEntityManagerFactoryBuilderOrNull(HibernatePersistence.java:93)
    at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:88)
    at org.hibernate.ejb.HibernatePersistence.getEntityManagerFactoryBuilderOrNull(HibernatePersistence.java:101)
    at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:69)
    ... 114 more

我也尝试过其他路径,例如lib / module1.jar,但结果总是一样的。如果重要,我们将使用Hibernate 4.3.5.Final。是什么给了什么?

更新

显然这是Hibernate中一个古老的错误:HHH4161。任何人都有一个很好的解决方法吗?从他们的Jira来看,这不会很快得到修复。

0 个答案:

没有答案