2

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.

Community
  • 1
  • 1
Markus Yrjölä
  • 859
  • 1
  • 12
  • 25
  • have you find any solution for this. I am also facing same issue. – Bhavesh Mar 19 '16 at 11:19
  • 1
    What Hibernate version are you using? [HHH-4161](https://hibernate.atlassian.net/browse/HHH-4161) was closed in 5.0.7, so you could try updating to that if you're on a lower version. We fixed it by making a patch for Hibernate that resolved the issue; we still have this patch in use. We also made a pull request for it, but it didn't work in all environments and was rejected. Later on the Hibernate team took it to themselves to fix the bug. So I'd say your best bet is to go for the latest version of Hibernate. – Markus Yrjölä Mar 21 '16 at 07:09

0 Answers0