The jpa error uses a non-entity [class ch.printsoft.mailhouse.usermgr.entity.Department] as the target in the relation attribute

I am trying to save the Department and Mandator classes in hsqhldb, but it gives this error.

 Exception Description: [class ch.printsoft.mailhouse.usermgr.entity.Mandator] uses a non-entity [class ch.printsoft.mailhouse.usermgr.entity.Department] as target entity in the relationship attribute [field departments]. at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:126) at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:115) at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source) at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source) 

These are the classes that I am trying to store in my database. I really don't know what the problem is.

 @Entity public class Mandator { @Id @GeneratedValue private Integer id; private String mandatorId; @OneToMany(mappedBy = "mandator") private List<MandatorUser> mandatorUsers; @OneToMany(mappedBy = "mandator") private List<SLAFamilyGroup> slaFamilyGroups; @OneToMany(mappedBy = "mandator") private List<Group> groups; @OneToMany(mappedBy = "mandator") private List<Department> departments; @OneToMany(mappedBy = "mandator") private List<CostUnit> costUnits; @Entity public class Department { @Id @GeneratedValue private Integer id; private String name; private String responsiblePerson; private String location; @ManyToOne(optional = false) private Mandator mandator; @ManyToMany private List<DocumentUser> documentUsers; 

I really tried everything, but that didn't work.

+15
source share
7 answers

Make sure you have both classes listed in your persistence.xml and both classes are in the classpath.

Please specify your persistence.xml.

+42
source

I just spent a lot of time debugging the seemingly inexplicable case of this exception, so I just leave my story here.

If you use a somewhat old implementation of JPA (for example, EclipseLink 2.5.x), and you use modern Java 8 functions (for example, lambda expressions) in your code base, you should never use them in JPA entity classes.

The EclipseLink 2.5 class metadata parser crashes when it encounters Java 8 functions (such as lambda expressions, method references, etc.) in bytecode. The internal failure is a very unfriendly ArrayIndexOutOfBoundsException , but you don’t even see it, because the weaver code silently ignores the metadata parser failures and simply assumes that the class does not contain interesting metadata. This leads us to believe that the class in question is not an entity, although it has all the relevant annotations, and the end result is the error message that we are talking about.

Bottom line: Do not use Java 8 iambda in JPA entity classes. EVER.

+41
source

I hope this can help someone.

I had the same problem. On the night before, everything was in order. In NetBeans, I checked, using History, all the files involved in the error. Persistence.xml is included. Nothing changed.

I also checked manually. I tried all the solutions proposed in this thread, even switch to eclipselink 2.6.4. I removed the 2 classes involved in the persistence.xml file, saved it, and added it again. The error was still there.

Then I deleted ALL classes in the list of entity classes included in persistence.xml, and then included them again.

Now it works. Magically.

But in fact, there was no difference in history. Even one character.

+3
source

Remove mappedBy from @OneToMany annotations from the Mandator class

Check if all related classes are displayed as @Entity. The department class has @ManyToMany related to DocumentUser. Provide a list of the DocumentUser class

+1
source

Make sure that both class files are in the same jar. Make sure you do not have two .class files with the same name!

0
source

Make sure that both classes have the PK property and the no parameter constructor. I am adding the following code to an entity class.

 @Entity public class EntityClass{ @Id @GeneratedValue(strategy=GenerationType.AUTO) public int id; public EntityClass() { } ... } 
0
source

Examine your mappedBy=xxx and make sure xxx is unique to the entire project.

0
source

All Articles