PropertyNotFoundException: Could not find a getter for lastMoveDate in class com.hib.objects.GameBoard

StackOverflow https://stackoverflow.com/questions/18073673

  •  23-06-2022
  •  | 
  •  

سؤال

I've named the class variable with camel casing.This is the class, which seems to be the culprit.

import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.sql.Date;

public class GameBoard
{
    @Temporal(TemporalType.DATE)
    private Date lastMoveDate;

    /**
     * @return the lastMoveDate
     */
    public Date getLastMoveDate() {
        return lastMoveDate;
    }

    /**
     * @param lastMoveDate the lastMoveDate to set
     */
    public void setLastMoveDate(Date lastMoveDate) {
        this.lastMoveDate = lastMoveDate;
    }

}

The class has several other variables such as playerOneFk, playerTwoFk and gameLobbyFk (hibernate is able to track each setter-getter on these variables, but is throwing exceptions with the last_move_date column).

I've also tried the method names setlastMoveDate and getlastMoveDate (with no luck..), The properties.. for lastMoveDate

<property name="lastMoveDate" type="date" column="last_move_date" />

And the caught exception

SEVERE: Servlet.service() for servlet [authapi] in context with path [/TTTserver] threw exception [Servlet execution threw an exception] with root cause
org.hibernate.PropertyNotFoundException: Could not find a getter for lastMoveDate in class com.hib.objects.GameBoard
    at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:282)
    at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:275)
    at org.hibernate.mapping.Property.getGetter(Property.java:272)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:247)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:125)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
    at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
    at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:295)
    at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
    at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
    at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
    at com.hib.objects.HibernateUtil.<clinit>(HibernateUtil.java:24)
    at nz.ac.massey.cs.capstone.auth.authapi.processRequest(authapi.java:42)
    at nz.ac.massey.cs.capstone.auth.authapi.doGet(authapi.java:74)
هل كانت مفيدة؟

المحلول

In Hibernate, the property type "date" maps to a java.sql.Date.

If you are using a java.util.Date, you will want your property type to be "timestamp".

Using "date" as you are now will cause it to look for a getter/setter that operates on a java.sql.Date, and it won't be able to find it.

See Hibernate basic type reference (6.1.1.12 and 6.1.1.14).

Edit: Addressing some naming convention concerns:

Hibernate obeys standard bean naming conventions:

  • Field: someField
  • Property: someField (same as field name)
  • Getter: getSomeField() or isSomeField() (if it is a boolean)
  • Setter: setSomeField()

نصائح أخرى

<property name="LastMoveDate" type="date" column="last_move_date" />

should work...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top