以下是两个hibernate映射文件:
Activity:
<?xml version="1.0" encoding="gb2312"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.ywt.domain"> <class name="Activity" table="activity" lazy="true"> <!-- id元素定义持久化类的标识属性 --> <id name="id"> <!-- 指定主键生成策略 --> <generator class="native" /> </id> <!-- property元素定义常规属性 --> <property name="name" not-null="true"/> <property name="time" not-null="true"/> <property name="imageurl" not-null="true"/> <property name="hostone" not-null="true"/> <property name="hosttwo" not-null="true"/> <property name="introduce" not-null="true"/> <property name="problem" /> <property name="award" /> <property name="schedule" /> <property name="number" /> <property name="status" not-null="true"/> <set name="studentSet" table="activity_student" inverse="true"> <key> <column name="A_ID"></column> </key> <many-to-many class="Student" column="S_ID" ></many-to-many> </set> </class> </hibernate-mapping>
Student:
<?xml version="1.0" encoding="gb2312"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.ywt.domain"> <!-- 每个class元素对应一个持久化对象 lazy="true" 代表加载延迟 对象A对对象B引用才会用到--> <class name="Student" table="student" lazy="true"> <!-- id元素定义持久化类的标识属性 --> <id name="id"> <!-- 指定主键生成策略 --> <generator class="native" /> </id> <!-- property元素定义常规属性 --> <property name="username" not-null="true"/> <property name="password" not-null="true"/> <property name="name" not-null="true"/> <property name="sex" not-null="true"/> <property name="major" not-null="true"/> <property name="academy" not-null="true"/> <property name="tel" /> <property name="coin"/> <property name="activities" /> <property name="honor" /> <set name="activitySet" table="activity_student"> <key> <column name="S_ID"></column> </key> <many-to-many class="Activity" column="A_ID"></many-to-many> </set> </class> </hibernate-mapping>
所出现的问题是:只要Activity映射文件中一加set集合就报如下错误(Student映射文件中加set不报错,已确认各属性书写没错误):
严重: Servlet.service() for servlet [mvc] in context with path [/dxshdw] threw exception [Handler processing failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.ywt.util.HibernateUtil] with root cause
java.lang.NoClassDefFoundError: Could not initialize class com.ywt.util.HibernateUtil
其中HibernateUtil是获取session工厂的类
lzjccc
叶为正啊
梦影剑魂
相关分类