我的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>
为什么我收到错误“无法找到布尔值的getter”以及需要进行哪些更改?
答案 0 :(得分:4)
遵循JavaBean命名约定,属性名称为“admin”。 “isAdmin”是属性的访问器方法的名称。