查看: 588|回复: 0

[Java语言] Hibernate创建映射文件时not found while looking for property错误

发表于 2018-2-4 10:14:26

最近在研究Hibernate。过程当中碰到了很多问题啊!其中一个就是not found while looking for property错误

Caused by: org.hibernate.MappingException: class main.java.POJO.User not found while looking for property: id

配置文件如下:

  1. <?xml version="1.0"?>
  2. <!DOCTYPE hibernate-mapping PUBLIC
  3. "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  4. "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
  5. <hibernate-mapping>
  6. <class name="entity/Employee" table="employee">
  7. <id name="eid" column="eid">
  8. <generator class="native"></generator>
  9. </id>
  10. <property name="ename" column="ename" length="20"></property>
  11. <property name="sex" column="sex" length="20"></property>
  12. <property name="birthday" column="birthday"></property>
  13. <property name="joinDate" column="joinDate"></property>
  14. <property name="eno" column="eno" length="20"></property>
  15. <property name="username" column="username" length="20"></property>
  16. <property name="password" column="password" length="20"></property>
  17. <!-- 关联关系映射(name为类中对应的属性) -->
  18. <many-to-one name="department" class="entity.Department" column="did"></many-to-one>
  19. </class>
  20. </hibernate-mapping>
复制代码

怎么看配置也没有问题啊!网上找了N久!终于在这篇文章里面看到了原因!
按照里面的方法把每个值都加上属性后就OK了

  1. <?xml version="1.0"?>
  2. <!DOCTYPE hibernate-mapping PUBLIC
  3. "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  4. "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
  5. <hibernate-mapping>
  6. <class name="entity/Employee" table="employee">
  7. <id name="eid" column="eid" type="java.lang.Integer">
  8. <generator class="native"></generator>
  9. </id>
  10. <property name="ename" column="ename" length="20" type="java.lang.String"></property>
  11. <property name="sex" column="sex" length="20" type="java.lang.String"></property>
  12. <property name="birthday" column="birthday" type="java.util.Date"></property>
  13. <property name="joinDate" column="joinDate" type="java.util.Date"></property>
  14. <property name="eno" column="eno" length="20" type="java.lang.String"></property>
  15. <property name="username" column="username" length="20" type="java.lang.String"></property>
  16. <property name="password" column="password" length="20" type="java.lang.String"></property>
  17. <!-- 关联关系映射(name为类中对应的属性) -->
  18. <many-to-one name="department" class="entity.Department" column="did"></many-to-one>
  19. </class>
  20. </hibernate-mapping>
复制代码


回复

使用道具 举报