在将映射文件User.hbm.xml、Role.hbm.xml和Department.hbm.xml文件添加到hibernate.cfg.xml后用于自动生成数据库表的时候抛出以下异常:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'roleDaoImpl': Injection of resource fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/jxust/oa/domain/User.hbm.xml
抛出此异常的原因:
在User.hbm.xml的映射文件中properties name="phoneNumber"写成了
properties name="phoneNumbers"
<hibernate-mapping package="com.jxust.oa.domain">
<class name="User" table="jxust_user">
<id name="id">
<generator class="native" />
</id>
<property name="loginName" />
<property name="password" />
<property name="name" />
<property name="gender" />
<property name="phoneNumber" />
<property name="email" />
<property name="description" />
<!-- department属性,本类与Department的多对一的关系 -->
<many-to-one name="department" class="Department" column="departmentId"></many-to-one>
<!-- roles属性 ,本类与Role的多对多的关系-->
</class>
</hibernate-mapping>
映射文件添加到hibernate.cfg.xml后抛出的异常
最新推荐文章于 2020-07-18 01:23:21 发布