I’m working on some example code to show different configuration options and approaches for using Hibernate with JPA. I just noticed that the location of the /META-INF/persistence.xml file is critical to allow Hibernate to auto-locate your annotated entities.
In order for the auto location to work (to avoid having to explicitly list annotated entities in your persistence.xml or hibernate.cfg.xml files), the persistence.xml file must be bundled in the same jar as the entities. If you move the file elsewhere, then the entities are not found, even if they are in the classpath. To workaround this, if you do need to put the persistence.xml file in a different location, use the <mapping> element to explicitly declare the entities.
Thank you! I always have entities and persistence.xml in the same JAR file, but it is nice to know that it works this way.