日期:2014-05-19 浏览次数:20625 次
org.hibernate.MappingException: Unknown entity: java.util.HashSet at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:628) at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1366) at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210) at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195) at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93) at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:563) at org.hibernate.impl.SessionImpl.save(SessionImpl.java:551) at org.hibernate.impl.SessionImpl.save(SessionImpl.java:547) at com.test.bean.TestHibernate.main(TestHibernate.java:79)
/** * 学生类 */ private String id; private String name; private int age; private Set<Course> course; /** * 班级类 */ private String id; private String name; private Set<Student> student; /** * 课程类 */ private String id; private String name; private Set<Student> student;
<class name="com.test.bean.Student" table="student"> <id name="id" column="id" type="string"> <generator class="uuid"/> </id> <property name="name" column="studentName" type="string"/> <property name="age" column="Studentage" type="int" /> <set name="course" table="student_course" cascade="all" > <key column="student_id"/> <many-to-many class="com.test.bean.Course" column="course_id" /> </set> </class>
<class name="com.test.bean.Course" table="course"> <id name="id" column="id" type="string"> <generator class="uuid"/> </id> <property name="name" column="courseName" type="string"/> <set name="student" table="student_course" cascade="all"> <key column="student_id"/> <many-to-many class="com.test.bean.Student" column="course_id" /> </set> </class>