Search code examples
hibernatejavabeans

Could not find a getter for boolean in Hibernate


My User model class is traditional as following:

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;
        }
    }

I am getting the below exception, while running it with 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)

Below is the Hibernate mapping configuration file:

<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>

Why I am getting the error "Could not find a getter for boolean" and what changes are required?


Solution

  • Following the JavaBean naming convention, the property name is "admin". "isAdmin" is the name of the accessor method for the property.