Hibernate recursive many-to-many association with the same entity

@ManyToMany to self is rather confusing because the way you’d normally model this differs from the “Hibernate” way. Your problem is you’re missing another collection. Think of it this way – if you’re mapping “author”https://stackoverflow.com/”book” as many-to-many, you need “authors” collection on Book and “books” collection on Author. In this case, your “User” entity represents … Read more

CDI: beans.xml, where do I put you?

For EJB and JAR packaging you should place the beans.xml in src/main/resources/META-INF/. For WAR packaging you should place the beans.xml in src/main/webapp/WEB-INF/. Remember that only .java files should be put in the src/main/java and src/test/java directories. Resources like .xml files should be in src/main/resources.

No Persistence provider for EntityManager named X

You must move persistence.xml file to an appropriate location. More specifically, add META-INF/persistence.xml file to the root of a source folder. In this case, the following is an appropriate location: src\main\java\META-INF\persistence.xml Here are the details: (taken from the JPA spec) A persistence.xml file defines a persistence unit. The persistence.xml file is located in the META-INF … Read more

Sharing a persistence unit across components in a .ear file

Here are the relevant sections of the JPA 2.0 specification: 8.2 Persistence Unit Packaging … A persistence unit is defined by a persistence.xml file. The jar file or directory whose META-INF directory contains the persistence.xml file is termed the root of the persistence unit. In Java EE environments, the root of a persistence unit must … Read more