1

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:

<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)
mahesh
  • 4,625
  • 11
  • 42
  • 61
  • 1
    Looks ok, try clean & compile again – jmj Jun 15 '12 at 06:03
  • doing the same clean & build process... and also have used same thing in other projects and works fine their.. – mahesh Jun 15 '12 at 06:05
  • it may sound kind of dumb, but sometimes you have to recompile to reflect changes, running the app may appear like it does it, but its better to do it explicitly some times. If that doesnt work delete the .class file and recompile. – Ed Morales Jun 15 '12 at 06:07
  • 1
    I hope there are no duplicate Address classes in the classpath – jmj Jun 15 '12 at 06:07
  • I have tried cleaning all class files and building it again but nothing is working for mew... – mahesh Jun 15 '12 at 06:27

5 Answers5

4

Hibernate could be a bit tricky with capitalization.

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

Grooveek
  • 10,046
  • 1
  • 27
  • 37
  • I tried the same as in some question that was the solution given..but that also not working in my case.. – mahesh Jun 15 '12 at 10:00
2

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.

ChaitanyaBhatt
  • 1,158
  • 14
  • 11
0

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.

0

Sometimes you have to put your aliases into escaped quotes (if you use resulttransformer that will inject aliased values into instances of Class via property methods or fields):

session
    .createNativeQuery("SELECT something AS /"someThing/"")
    .setResultTransformer(Transformers.aliasToBean(MyDao.class))
    .getResultList();
Zon
  • 18,610
  • 7
  • 91
  • 99
0

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.

So I delete the duplicate classes

alan9uo
  • 1,011
  • 1
  • 11
  • 17