4

我的User模型类是传统的如下:

package org.ravij.model;

    public class User {

        private String username;
        private String password;
        private boolean isAdmin;

        public boolean isAdmin() {
            return isAdmin;
        }

        public void setAdmin(boolean isAdmin) {
            this.isAdmin = isAdmin;
        }

        public String getUsername() {
            return username;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }
    }

在使用 Hibernate v4.2 运行它时,我遇到了以下异常:

Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for isAdmin in class org.ravij.model.User
    at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:316)
    at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:310)
    at org.hibernate.mapping.Property.getGetter(Property.java:321)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:436)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:200)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:82)

下面是 Hibernate 映射配置文件:

<hibernate-mapping package="org.ravij.model">

    <class name="User" table="Users">
        <id name="username" type="string" column="User_Name" length="20">
            <generator class="assigned" />
        </id>
        <property name="password" type="string" column="Password" />
        <property name="isAdmin" column="Admin" type="boolean" />
    </class>

</hibernate-mapping>

为什么我收到错误“找不到布尔值的吸气剂”以及需要进行哪些更改?

4

1 回答 1

5

按照 JavaBean 命名约定,属性名称为“admin”。“isAdmin”是属性的访问器方法的名称。

于 2013-03-26T20:59:13.340 回答