• 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

Handling Null values in Java Primitive DATA types

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi There, we got a strange scenario in our Hibernate based web application.

On the Database SQL Server 2005,there is a field called user_type of Boolean type and it will store True or False messages and this Data Base SQL Server2005 allows to store "NULL" into this field which is very strange.
When run a HQL Query and set these values into Bean Hibernate will through exceptions saying

I am not sure how to handle this scenario.
In the first case how come DB SQL Server2005 is allowing to store "NULL" values into Primitive types and Hibernate/Java or any programming language cannot/impossible to store NULL into primitive data types.
Any arguments/answers please.
Thanks in advance,VijayGadde
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can consider using wrappers for mapping.
 
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


On the Database SQL Server 2005,there is a field called user_type of Boolean type and it will store True or False messages and this Data Base SQL Server2005 allows to store "NULL" into this field which is very strange.


Why is that strange? Presumably if you want to use a boolean type with a nullable field then the value can be null?

As a general rule, if you have mapped a primitive type to any field that is nullable your mapping is wrong.
[ October 15, 2008: Message edited by: Paul Sturrock ]
 
Vijay Gadde
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that postings..!

Now I had Fixed this NULL issues in my application.

If one declares these int,bit,char as Primitive data types in POJO classes.. then we cannot do getter/setter NULL value into this attributes.. but on you these values will allow NULL to store.. so to avoid this conflicts its always suggestible to use WRAPPER classes itself not Primitive types.

What I had observed.. On the DB we have inter, bit types.

How do we need declare them in our Hibernate POJO classes

> Point1: We would need to initialize these variable with WRAPPER classes only
like int - "Integer"
bit - "Boolean"
char - "Character"

does any one dis-agree with this, any comments/suggestions please..!
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am getting same problem .
FATAL [reviewBoard] Error in getReviewBoardDetails() in ReviewBoardAgentBeanjavax.persistence.PersistenceException: org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.velos.eres.business.reviewboard.impl.ReviewBoardBean.reviewboardAccId

In this case, i am trying to get name of all Review Board Names.When i click on records inserted by form , i am able to get those records Name , but when i am trying to get records that were inserted in table as seed data.I am getting this error?
I am using "int" in my "ReviewBoardJB.java" file. I am not getting if this is error due to primitive data-type, then why it work with others that records inserted by form.
Please guide me how to solve this.

Thanks,
Amit Kumar Srivastava

 
Greenhorn
Posts: 1
Hibernate Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems there is null values when you retireve from the table and hence the error, whereas when you enter from the form you enter values for all the fields. Use wrappers for all primitives in your class.
 
There's a way to do it better - find it. -Edison. A better tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic