为了账号安全,请及时绑定邮箱和手机立即绑定

Hibernate创建映射文件时not found while looking for property错误

标签:
Java MySQL

最近在研究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"?>  
<!DOCTYPE hibernate-mapping PUBLIC   
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"  
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">      
<hibernate-mapping>   
    <class name="entity/Employee" table="employee">
        <id name="eid" column="eid">
            <generator class="native"></generator>
        </id>
        <property name="ename" column="ename" length="20"></property>
        <property name="sex" column="sex" length="20"></property>
        <property name="birthday" column="birthday"></property>
        <property name="joinDate" column="joinDate"></property>
        <property name="eno" column="eno" length="20"></property>
        <property name="username" column="username" length="20"></property>
        <property name="password" column="password" length="20"></property>

        <!-- 关联关系映射(name为类中对应的属性) -->
        <many-to-one name="department" class="entity.Department" column="did"></many-to-one>
    </class>
</hibernate-mapping>  

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

<?xml version="1.0"?>  
<!DOCTYPE hibernate-mapping PUBLIC   
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"  
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">      
<hibernate-mapping>   
    <class name="entity/Employee" table="employee">
        <id name="eid" column="eid" type="java.lang.Integer">
            <generator class="native"></generator>
        </id>
        <property name="ename" column="ename" length="20" type="java.lang.String"></property>
        <property name="sex" column="sex" length="20" type="java.lang.String"></property>
        <property name="birthday" column="birthday" type="java.util.Date"></property>
        <property name="joinDate" column="joinDate" type="java.util.Date"></property>
        <property name="eno" column="eno" length="20" type="java.lang.String"></property>
        <property name="username" column="username" length="20" type="java.lang.String"></property>
        <property name="password" column="password" length="20" type="java.lang.String"></property>

        <!-- 关联关系映射(name为类中对应的属性) -->
        <many-to-one name="department" class="entity.Department" column="did"></many-to-one>
    </class>
</hibernate-mapping>  
点击查看更多内容
3人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消