Saturday, October 5, 2013

Hibernate Error :  failed.org.hibernate.PropertyNotFoundException: Could not find a getter for firstname in class net.viralpatel.contact.model.Contact

I get below error in a struts 2 + hibernate 3 project and below is mapping file.

<property name="firstname" type="string" not-null="false" length="30" column="firstName" />

And below is how the domain class property is named.

private String firstName;

Below is how column in DB is named.

firstName   VARCHAR(30)

when execute the add action from jsp page i get below error.

failed.org.hibernate.PropertyNotFoundException: Could not find a getter for firstname in class net.viralpatel.contact.model.Contact
Oct 6, 2013 11:51:32 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet default threw exception
org.hibernate.PropertyNotFoundException: Could not find a getter for firstname in class net.viralpatel.contact.model.Contact
    at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:306)
    at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:299)
    at org.hibernate.mapping.Property.getGetter(Property.java:294)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:268)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:148)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:76)
    at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:80)
    at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:325)
    at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:457)
    at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:131)
    at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:261)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
    at net.viralpatel.contact.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:14)
    at net.viralpatel.contact.util.HibernateUtil.<clinit>(HibernateUtil.java:8)
    at net.viralpatel.contact.view.ContactAction.<init>(ContactAction.java:21)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:355)
    at java.lang.Class.newInstance(Class.java:308)
    at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:130)......................

Solution :

Property in hbm and pojo class are different.
They should be the same.

No comments:

Post a Comment