-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: How can I map boolean values stored as text on the database?
PostPosted: Wed Jul 05, 2006 10:26 am 
Newbie

Joined: Wed Jul 05, 2006 10:14 am
Posts: 7
Hi,
we have a database in wich boolean values are stored as text (varchar or char). So, if we want to store a true value, we store something like 'Y', and for false, something like 'N', so when we need these data, we can make a simple conversion inside our own code.
But now we are using Hibernate (and loving it!). So here is my question: how can I map these values stored as text to boolean values?
Is it possible? How can we do it?

Hibernate version: 3.2 RC

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using: MySQL 5.0.22

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

_________________
Henrique Lobo Weissmann


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 10:32 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
I use something like this with the same requirement

Code:
<property name="columnProperty" column="MY_DB_COLUMN" type="yes_no" />


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 11:08 am 
Newbie

Joined: Mon Jun 13, 2005 11:02 pm
Posts: 3
type="yes_no" for SQL CHAR(1) type where the field contains {'Y','N'}
type="true_false" for SQL CHAR(1) type where the field contains {'T','F'}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 3:01 pm 
Newbie

Joined: Wed Jul 05, 2006 2:26 pm
Posts: 5
JayH wrote:
type="yes_no" for SQL CHAR(1) type where the field contains {'Y','N'}
type="true_false" for SQL CHAR(1) type where the field contains {'T','F'}


Can you do this if the column is of type enum('TRUE', 'FALSE')? We have some existing tables that do this. We also have a bunch that use and integer 0 for false and integer 1 for true. I am trying to avoid writing a custom UserType class, and would like to return a boolean or a Boolean.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.