最近在研究Hibernate。过程当中碰到了很多问题啊!其中一个就是not found while looking for property错误
Caused by: org.hibernate.MappingException: class main.java.POJO.User not found while looking for property: id
配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="main.java.POJO">
<class name="User" table="loginuser">
<id name="id" column="Id" >
<generator class="native"/>
</id>
<property name="username" column="username" />
<property name="password" column="password" />
<property name="sex" column="sex" />
</class>
</hibernate-mapping>
怎么看配置也没有问题啊!网上找了N久!终于在这篇文章里面看到了原因!
按照里面的方法把每个值都加上属性后就OK了
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="main.java.POJO">
<class name="User" table="loginuser">
<id name="id" column="Id" type="java.lang.Integer">
<generator class="native"/>
</id>
<property name="username" column="username" type="java.lang.String"/>
<property name="password" column="password" type="java.lang.String"/>
<property name="sex" column="sex" type="java.lang.String"/>
</class>
</hibernate-mapping>
特记于此!以备勿忘!