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

My Address Class:

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

我的hbm.xml文件:

My hbm.xml file:

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


推荐答案

Hibernate对于大写字母可能有点棘手。

Hibernate could be a bit tricky with capitalization.

尝试将CustomerId作为属性名称,并且所有内容都应该没问题。如果你为属性 customerID

Try CustomerId as a property name, and all should be fine. Hibernate expects a getcustomerId method if you name the property customerID

这篇关于org.hibernate.PropertyNotFoundException:在类Address中无法找到customerId的getter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 08:57