本文介绍了PropertyNotFoundException:在类com.hib.objects.GameBoard中找不到lastMoveDate的getter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

public class GameBoard
{
@Temporal(TemporalType.DATE)
private date lastMoveDate;
$ b $ **
* @return lastMoveDate
* /
public Date getLastMoveDate(){
return lastMoveDate;

$ b $ **
* @param lastMoveDate lastMoveDate设置
* /
public void setLastMoveDate(Date lastMoveDate){
this.lastMoveDate = lastMoveDate;
}

}

该类还有其他几个变量作为 playerOneFk playerTwoFk gameLobbyFk (hibernate能够追踪这些变量上的每一个 setter-getter ,但是会抛出异常< last_move_date 列)。



我也尝试过方法名称 setlastMoveDate getlastMoveDate lastMoveDate

 < property name =lastMoveDatetype =datecolumn =last_move_date/> 

并且发现异常

  SEVERE:Servlet.service()用于上下文中的servlet [authapi] [/ TTTserver]抛出异常[Servlet执行抛出异常],其根源为
org.hibernate.PropertyNotFoundException:可能在类com.hib.objects.GameBoard中找不到getter for lastMoveDate
在org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:282)
在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)
在org.hibernate.tuple.entity.EntityEntityM < 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.au thapi.doGet(authapi.java:74)


解决方案

Hibernate,属性类型date映射到java.sql.Date。



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

现在使用date会导致它寻找一个在java.sql.Date上运行的getter / setter,它将无法找到它。



请参阅(6.1.1.12和6.1.1.14)。

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



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




  • 字段:someField

  • 属性:someField(与字段名相同)
  • getter:getSomeField()或isSomeField() (如果它是布尔型的)

  • setter:setSomeField()


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

这篇关于PropertyNotFoundException:在类com.hib.objects.GameBoard中找不到lastMoveDate的getter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 08:56