We have a Java EE project consisting of multiple JARs, several of them containing entities. The app is packaged as an EAR with the following structure:
app.ear
lib/core.jar (containing META-INF/persistence.xml)
lib/module1.jar (contains entities)
lib/module2.jar (contains entities)
...
In the persistence.xml, we try to reference to the JAR files that contain the entities like this:
<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>
I took a look at the JPA 2.1 spec (also referenced to in this SO answer), and my configuration should be correct, right? Our setup corresponds to the Example 2 in the JPA spec section 8.2.1.6.3. However, when I deploy the app, I get this error message:
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
I've tried with other paths as well, e.g. lib/module1.jar, but the result is always the same. In case it matters, we're using Hibernate 4.3.5.Final. What gives?
UPDATE:
Apparently this is an age-old bug in Hibernate: HHH4161. Anyone have a good workaround for this? Judging from their Jira, this isn't going to be fixed anytime soon.