Tuesday, July 13, 2010

Null value was assigned to a property of primitive type setter of

While fetching data from database using jpa and hibernate I got one error and this is

org.springframework.orm.jpa.JpaSystemException: org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.ayush.suman.bo.Address.trusted; nested exception is javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.ayush.suman.bo.Address.trusted

My Address.java was like this:

@Entity
@Table(name="address")
public class Address {

@Id
private long id;
private String address;
@Column(name="country_code")
private String countryCode;
@Column(name="address_type")
private String addressType;

private int trusted;

with getter and setter methods

}

Solution:

Just change int to Integer simple ....... :)

Now updated Address.java

@Table(name="address")
public class Address {

@Id
private long id;
private String address;
@Column(name="country_code")
private String countryCode;
@Column(name="address_type")
private String addressType;

private Integer trusted;

with getter and setter methods

}

Dont forgate to change int to Integer in setter and getter method of trusted field.

Turning off hibernate logging console output, How to hide/disable Hibernate log to console

Just sharing my experiance with Hibernate 3.0.

Even after using the log4j.xml with

<logger name="org.hibernate">
<level value="info"/>
</logger>


I could not able to trun off the huge hibernate log on console, it was coming like this:

7 [main] INFO org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.4.0.GA
37 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.0.SP1
43 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
48 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
52 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
163 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.1.0.GA
168 [main] INFO org.hibernate.ejb.Version - Hibernate EntityManager 3.4.0.GA
202 [main] INFO org.hibernate.ejb.Ejb3Configuration - Processing PersistenceUnitInfo [

name: VMSPersistenceUnit

...]



Finally I got solution and that is here:

Just add slf4j-log4j12-1.5.2.jar in your classpath if you are using slf4j-api. Actually SLF4J is used by hibernate and if you are using log4j you need to setup the bridge for your logging system.



In my case, I have these jar files in my project classpath:


slf4j-api-1.5.6.jar
slf4j-log4j12-1.5.6.jar
slf4j-simple-1.4.2.jar


Thats it ...... :)