java org.hibernate.PropertyNotFoundException:在类 Address 中找不到 customerId 的 getter
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11045372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
org.hibernate.PropertyNotFoundException: could not find getter for customerId in class Address
提问by mahesh
My Address Class:
我的地址类:
public class Address implements java.io.Serializable {
private String addressId;
private String customerId;
public Address() {
}
public Address(String addressId) {
this.addressId = addressId;
}
public Address(String addressId, String customerId) {
this.addressId = addressId;
this.customerId = customerId;
public String getAddressId() {
return this.addressId;
}
public void setAddressId(String addressId) {
this.addressId = addressId;
}
public String getCustomerId() {
return this.customerId;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
My hbm.xml file:
我的 hbm.xml 文件:
<class name="Address" table="Address">
<id name="addressId" column="address_id" type="java.lang.String">
<generator class="assigned" />
</id>
<property name="customerId" column="customer_id" type="java.lang.String" />
</class>
I am getting following error
我收到以下错误
org.hibernate.PropertyNotFoundException: Could not find a getter for customerId in class Address
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:302)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
回答by Grooveek
Hibernate could be a bit tricky with capitalization.
Hibernate 的大小写可能有点棘手。
Try CustomerId as a property name, and all should be fine. Hibernate expects a getcustomerId
method if you name the property customerID
尝试将 CustomerId 作为属性名称,一切都应该没问题。getcustomerId
如果您命名属性,Hibernate 需要一个方法customerID
回答by ChaitanyaBhatt
This could happen if you do not set the default attribute in hibernate.hbm.xml file but you have a default value specified for the column in the database.
如果您没有在 hibernate.hbm.xml 文件中设置默认属性,但您为数据库中的列指定了默认值,则可能会发生这种情况。
回答by alkimisticus
If you have web aplication in eclipse check that you have same output folder in the java build path and same source folder in Deployment Assembly.
如果您在 Eclipse 中有 Web 应用程序,请检查您在 java 构建路径中是否具有相同的输出文件夹,在部署程序集中是否具有相同的源文件夹。
回答by Zon
Sometimes you have to put your aliases into escaped quotes(if you use resulttransformerthat will inject aliased values into instances of Class via property methods or fields):
有时您必须将别名放入转义引号中(如果您使用resulttransformer,它将通过属性方法或字段将别名值注入到 Class 的实例中):
session
.createNativeQuery("SELECT something AS /"someThing/"")
.setResultTransformer(Transformers.aliasToBean(MyDao.class))
.getResultList();
回答by alan9uo
In my case. I found there were duplicate classes in my war and jar.Like Jigar Joshi said. Why this happend? I move some entity to other project that package into a jar file . And I re-deploy my project by war, Tomcat didn't delete the entity class that I remove, the entity class still in the old place and those duplicate with my jar files.
就我而言。我发现我的 war 和 jar 中有重复的类。就像 Jigar Joshi 说的。为什么会这样?我将一些实体移动到打包成 jar 文件的其他项目中。我通过War重新部署了我的项目,Tomcat 没有删除我删除的实体类,实体类仍然在旧位置,而那些与我的 jar 文件重复的实体类。
So I delete the duplicate classes
所以我删除了重复的类