Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error if we have null values in data base table

 
Sekhar Chand
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,
i am new to hibernate. I tried to work with hibernate with small example.
Just i am retrieving data from emp table. There we have null values in comm column. When i am retrieving data from that table, if it is null value, it is giving error like "Null value was assigned to a property of primitive type setter of smallexample.Emp2.comm". where Emp2 is pojo and comm is data member.
Please give me the relevant soilution as soon as possible

With regards
Ratna sekhar
 
saranga rao
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is where hibernate stop think............

Error will like to be CGILib error .........in hiberante...........

the temprory solution is dont leave the column null insert the value like '0' or any value.......and manpulate in java code...............

I have got like this type of error.............but this is one of disadavantge.......database can keep null value...also......but hibernate will not allow.....
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

here we have null values in comm column. When i am retrieving data from that table, if it is null value, it is giving error like "Null value was assigned to a property of primitive type setter of smallexample.Emp2.comm"

Primitives cannot have null values, so don't map a nullable field to a primitive type.
 
saranga rao
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Paul

Primitives cannot have null values, so don't map a nullable field to a primitive type....

if for examples there is a column called age-between = "string" (19-20)with default is "null" then also it will throw....... if you keep blank..then defently it will throw...the error
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure I follow saranga rao. A String is not a primitive type.
 
pradeep setti
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,I have tried with inserting a null value in the column where we have to put string actually.And got the inserted value from the db back and i has run fine.I am attaching the code snippet for your reference:

this is my bean class using which i am inserting null value into the db:

Department dept1 = new Department();
dept1.setDeptid(10);
dept1.setDeptname(null);
dept1.setManager("Prasad");


System.out.println("Getting data back from the db::");
Iterator iter = session.createCriteria(testcascadeemp.com.prads.Department.class).list().iterator();
while(iter.hasNext()){
Department deptmnt = (Department)iter.next();
System.out.println("Getting the "+deptmnt.getManager()+" Department::"+deptmnt.getDeptname());
}


here is the output it gave:

Getting the Ramana Department: evelopment
Getting the Ganesh Department: roduction
Getting the Thandav Department::Testing
Getting the Rakesh Department::HR
Getting the Rakesh Department::HR
Getting the Rakesh Department::HR
Getting the Prasad Department::null
 
pradeep setti
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,I have used hibernate3.2.3 version for this scenario.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic