PropertyNotFoundException:在com.hib.objects.GameBoard类中找不到lastMoveDate的getter

时间:2013-08-06 07:03:49

标签: java hibernate getter-setter

我用camel casing命名了这个类变量。这是类,它似乎是罪魁祸首。

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

}

该类还有其他几个变量,例如playerOneFkplayerTwoFkgameLobbyFk(hibernate能够跟踪这些变量上的每个setter-getter,但是会抛出异常last_move_date列。)

我还尝试了方法名称setlastMoveDategetlastMoveDate(没有运气..),lastMoveDate的属性..

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

捕获的异常

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)

2 个答案:

答案 0 :(得分:2)

在Hibernate中,属性类型“date”映射到java.sql.Date。

如果您使用的是java.util.Date,则需要将属性类型设置为“timestamp”。

现在使用“date”将导致它查找在java.sql.Date上运行的getter / setter,它将无法找到它。

Hibernate basic type reference(6.1.1.12和6.1.1.14)。

编辑:解决一些命名约定问题:

Hibernate遵循标准的bean命名约定:

  • 字段:someField
  • 属性:someField(与字段名称相同)
  • Getter:getSomeField()或isSomeField()(如果是布尔值)
  • Setter:setSomeField()

答案 1 :(得分:1)

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

应该有用......