org.hibernate.PropertyNotFoundException:在com.hibernate.demo.user类中找不到firstname的getter

时间:2018-06-14 18:02:44

标签: hibernate hibernate-mapping

我已经为firstname变量编写了getter方法,但它再次引发异常。请告诉我如何处理这个问题。我已经谷歌了,但在这些解决方案中总是缺少行,但在我的情况下,我已经定义了setter getter方法。

package com.hibernate.demo;

public class user 
{
    private int id;
    private String firstname, lastname;

    public int getId()
    {
        return id;
    }
    public void setId(int id)
    {
        this.id=id;
    }
    public String getFirstName()
    {
        return firstname;
    }
    public void setFirstName(String firstname)
    {
        this.firstname=firstname;
    }
    public String getLastName()
    {
        return lastname;
    }
    public void setLastName(String lastname)
    {
        this.lastname=lastname;
    }
}

属性文件是

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.hibernate.demo.user" table="users">
        <id name="id" type="int" column="id">
            <generator class="native"/>
        </id>
        <property name="firstname">
            <column name="firstname"/>
        </property>
        <property name="lastname">
            <column name="lastname"/>
        </property>
</class>

1 个答案:

答案 0 :(得分:0)

您的媒体资源名为firstname,因此应将调用方法称为getFirstname(),而不是getFirstName()。同样的情况是lastname