开发者

WrongClassException when assigning entries on one side of many to many relationship

开发者 https://www.devze.com 2023-03-27 11:36 出处:网络
I\'m using Spring Roo (and Hibernate) for a web application. I\'ve got two entitieswhich have a MANY-TO-MANY relationship:

I'm using Spring Roo (and Hibernate) for a web application.

I've got two entities which have a MANY-TO-MANY relationship:

public class Student{
   @ManyToMany(cascade = CascadeType.ALL,mappedBy="students")
   private Set<Course> courses = new HashSet<Course>();
}

public class Course{
   @ManyToMany(cascade = CascadeType.ALL)
   private Set<Student> students = new HashSet<Student>();
}

In the scaffolded GUI I can assign multiple courses to students, but when I try to assign students to courses I get this error:

org.hibernate.WrongClassException: Object with id: null was not of the specified sub开发者_运维知识库class: com.company.Student(class of the given object did not match class of persistent copy); nested exception is javax.persistence.PersistenceException: org.hibernate.WrongClassException: Object with id: null was not of the specified subclass: com.company.Student(class of the given object did not match class of persistent copy)

What may be the cause of the problem?


By just looking at the syntax, try setting the value for the mappedBy property in the @ManyToMany annotation within the Course class.


I got a WrongClassException by trying to save an @Entity object which was using the same @DiscriminatorValue as another class.

0

精彩评论

暂无评论...
验证码 换一张
取 消