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.
精彩评论