gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 05:39:44 25 4
gpt4 key购买 nike

我用驼峰式命名了类变量。这就是类,这似乎是罪魁祸首。

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 的属性../p>

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

最佳答案

在 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(同字段名)
  • Getter:getSomeField() 或 isSomeField()(如果它是 boolean 值)
  • 二传手:setSomeField()

关于java - PropertyNotFoundException : Could not find a getter for lastMoveDate in class com. hib.objects.GameBoard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18073673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com