• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

error if we have null values in data base table

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.....
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure I follow saranga rao. A String is not a primitive type.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,I have used hibernate3.2.3 version for this scenario.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic