I try to persist my Department
and Mandator
classes to 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 try to persist to 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've really tried every thing but it didn't work.
I just spent a lot of time debugging a seemingly unexplainable case of this exception, so I'm just leaving my story here.
If you're using a somewhat old implementation of JPA (e.g. EclipseLink 2.5.x) and you're using modern Java 8 features (such as lambda expressions) in your code base - don't ever use them in the JPA entity classes.
EclipseLink 2.5's class metadata parser crashes upon encountering Java 8 features (such as lambda expressions, method references etc.) in the bytecode. The internal crash is a very unfriendly ArrayIndexOutOfBoundsException
, but you don't even get to see it, as the weaver code silently ignores metadata parser crashes and just assumes the class has no interesting metadata. This leads it to believe that the class in question is not an entity even though it has all the proper annotations, and the end result is the error message we are talking about.
Bottom line: Don't use Java 8 lambdas in JPA entity classes. EVER.
Ensure you have both classes listed in your persistence.xml, and the both classes are on the classpath.
Please include your persistence.xml.
I hope this can help someone.
I had the same problem. The night before, everything was ok. In NetBeans I've checked, using History, all the files involved in the error. Persistence.xml included. Nothing was changed.
I've checked also manually. I've tryed all the solution suggested in this thread even migrate to eclipselink 2.6.4. I've removed the 2 class involved in the persistence.xml, saved it, and added again. The error was still there.
Then, I've removed ALL the classess in the list of the Entity Classes included in the persistence.xml, and then I've included them again.
Now it works. Magically.
But really there were non difference in the history. Even a single character.
Ensure you have defined both classes are under < persistence-unit > tag of persistence.xml file. As we know At the time of persistence the entity into DB. Our Application finds the entity classes information from persistence.xml file. If entity's mapping is not found in persistence.xml, then application throw this exception while you will perform any operation on that entity like here your are.
So Please make both entities entry in your persistence.xml
Example: persistence.xml :-
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="mapping_unit">
<class>ch.printsoft.mailhouse.usermgr.entity.Mandator </class>
<class>ch.printsoft.mailhouse.usermgr.entity.Department</class>
...
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/practice" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
<property name="eclipselink.logging.level" value="SEVERE" />
<property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
</properties>
</persistence-unit>
</persistence>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With