readthefuckingmanual.net

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

Error added: 2008-02-26T14:16:17Z

3 people waiting for the answer...

10 answers found.

Answer 613 (86.36363% helpful)

I have the same problem. The problems was that the value in the database was NULL so when Hibernate try to set the value NULL from the DB to the set method which accept a primitive value it throw an error.

Solution:
Change the set to Integer or set the value in the DB to be No Null and set some default value.

 
Permalink

Answer 519 (80.95238% helpful)

Set the field to be java.lang.Integer rather than int
Permalink

Answer 1166 (66.666664% helpful)

Answer 1 worked for me. 

Example segment from mapping *hbm.xml file: ...

<property name=\"myVar\" type=\"int\">
        <column name=\"MYCOLUMN\" not-null=\"false\"/>
</property>

------
Relevant variable definition in mapping class.

Integer myvar;

public Integer getMyvar() {
        return myvar;
}

public void setMyvar(Integer myvar) {
        this.myvar = myvar;
}


Permalink

Answer 1353 (66.666664% helpful)

Answer 8 worked for me for MS SQL.

\"If your object has a primitive-type property mapped to a nullable database column then you will need to use a Hibernate custom type to assign a sensible default (primitive) value for the case of a null column value. A better solution is usually to use a wrapper type for the Java property.\"
Permalink

Answer 1272 (50.0% helpful)

Answer 1 worked for me when i used Double at the place of double and Character at the place of char.
If ur value is become nullable then dont use primtive type.

If your object has a primitive-type property mapped to a nullable database column then you will need to use a Hibernate custom type to assign a sensible default (primitive) value for the case of a null column value. A better solution is usually to use a wrapper type for the Java property.
Permalink

Answer 1705 (0.0% helpful)

Answer2 worked for me too.

Thank u
Permalink

Answer 1060 (0.0% helpful)

Answer 2 is the perfect solution to the problem
Permalink

Answer 1097 (0.0% helpful)

ans 2 is right when i am using Oracle 10g with Hibernate 3.0
Permalink

Answer 1126 (0.0% helpful)

use formula=\"ifnull(columnname,0)\" for int/long datatype in the property element
Permalink

Answer 1271 (0.0% helpful)

Answer 1 worked for me when i used Double at the place of double and Character at the place of char.
If ur value is become nullable then dont use primtive type.

If your object has a primitive-type property mapped to a nullable database column then you will need to use a Hibernate custom type to assign a sensible default (primitive) value for the case of a null column value. A better solution is usually to use a wrapper type for the Java property.
Permalink

Add an answer/solution

If you know the answer, please add your own solution below.
If you don't know, but find out later, please come back and share your answer - there will be other people struggling with this too.


Please enter 61948 here

If you want to be notified via email when this is solved, enter your email address here: