Autodetect classes in Hibernate from jar
hibernate, jakarta-ee, java, jboss
Solution
If I read you correctly, in the case where it does not work, the entities are in a different JAR than the persistence.xml that's used, right?
I think you're correct that's the problem. You need to tell Hibernate which JAR(s) to scan using the jar-file element. See the explanation and examples in the Hibernate docs here
Problem
I have a JavaEE project with several entities with the following `persistence.xml` file: ``` ... <properties> <!-- Scan for annotated classes --> <property name="hibernate.archive.autodetection" value="class"/> ... ``` And it seems to work. The project is then deployed as a JAR to two different projects. In one them, the `persistence.xml` file is basically the same as the one above, i.e. uses the `autodetection` feature of Hibernate. However, it does not seem to work (because I think it needs to load search for the entities in a jar). When I tried manually listing all the entities in both xml files, everything works correctly. Edit: It works with jar-file but only with the absolute path to the jar. Pretty useless for a team project.