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

前端 未结 8 612
北海茫月
北海茫月 2020-12-18 19:17

I try to persist my Department and Mandator classes to hsqhldb but it gives this error.

Exception Description: [class ch.printsoft.         


        
相关标签:
8条回答
  • 2020-12-18 19:34

    Make sure that both "class" files are in the same jar. Make sure that you don't have two .class files with the same name !

    0 讨论(0)
  • 2020-12-18 19:41

    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.

    0 讨论(0)
  • 2020-12-18 19:49

    Ensure you have both classes has the property of PK and the no parameter constructor. I add the following code in my entity class.

    @Entity
    public class EntityClass{
       @Id
       @GeneratedValue(strategy=GenerationType.AUTO)
       public int id;
       public EntityClass() {
       } 
       ...
    }
    
    0 讨论(0)
  • 2020-12-18 19:54

    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.

    0 讨论(0)
  • 2020-12-18 19:54

    Examine your mappedBy=xxx and make sure xxx is unique in whole project.

    0 讨论(0)
  • 2020-12-18 19:55

    Ensure you have both classes listed in your persistence.xml, and the both classes are on the classpath.

    Please include your persistence.xml.

    0 讨论(0)
提交回复
热议问题