aspose file tools*
The moose likes Object Relational Mapping and the fly likes error if we have null values in data base table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "error if we have null values in data base table" Watch "error if we have null values in data base table" New topic
Author

error if we have null values in data base table

Sekhar Chand
Ranch Hand

Joined: Apr 05, 2006
Posts: 73
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

Joined: Apr 24, 2007
Posts: 49
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

Joined: Apr 14, 2004
Posts: 10336


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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
saranga rao
Ranch Hand

Joined: Apr 24, 2007
Posts: 49
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

Joined: Apr 14, 2004
Posts: 10336

Not sure I follow saranga rao. A String is not a primitive type.
pradeep setti
Greenhorn

Joined: Jul 12, 2006
Posts: 9
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

Joined: Jul 12, 2006
Posts: 9
Paul,I have used hibernate3.2.3 version for this scenario.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error if we have null values in data base table