• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Annotation Yes/No

 
ambaldhage ravi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a database column with number(1) which stores 0/1/null values.
1)While displaying the values in the page I have to get yes for 1, no for 0 and blank for null.
2)While displaying the values in the page I have to get Retail for 0, Corporate for 1 and blank for null.
Is it possible in the hibernate using annotations in the DAO class?
For the first problem i used yesnotype annotation but it is displaying true/false I require yes/no.
Please help me.
 
Tim Holloway
Saloon Keeper
Posts: 18367
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use of NULL in a database is something I strongly discourage. NULL isn't a value, it's an absence of a value, and there are all sorts of downsides to that. I only use NULL to indicate that there's no data available when not having data should be considered an exceptional condition.

Bibernate objects are Java objects, and thus Hibernate can use boolean data types (WARNING - not all databases support binary column types!).

The two fundamental boolean data types are the boolean primitive and the java.lang.Boolean wrapper class. The primitive cannot be null - that's one of the distinguishing characteristics of Java primitives. A java.lang.Boolean object, however, can be null, so that's what you'd use.

HTML doesn't support tri-state checkboxes, which is another reason why I don't recommend using a boolean datatype when you expect to see 3 different values (or 2 values and a non-value, if you prefer).
 
Raja Nagendra Kumar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could override the get method of the boolean variable to return yes or no..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic