Thursday, September 30, 2010

org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter

Kind Of Exception :

org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.java.portal.payment.pojo.Payment.paymentID
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:85)
ate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3571)       
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:129)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:96)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1573)
org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$.processConnection(Http11Protocol.java:705)
org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter

Reason Of Exception :

This kind of exception mainly occurs when you are using Hibernate and the property in your POJO is of primitive type i.e int etc. and “null” is coming in it while setting.

Solution Of Exception :

1) The first solution for the above problem is to change the value of the column of the table from which “null” is coming to a not null value and set the column to NOT NULL.

2) The second solution is to not use primitive data types for properties of POJO instead use types like java.lang.Integer.

No comments:

Post a Comment