-->
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.  [ 5 posts ] 
Author Message
 Post subject: (Hibernate with JPA) data conversion between DB and java
PostPosted: Mon Oct 01, 2007 11:25 am 
Beginner
Beginner

Joined: Tue May 11, 2004 12:20 am
Posts: 33
I'm using Hibernate through JPA interface (EntityManager), and would appreciate it if anyone could help with the following question:

What is the recommended way to define a conversion rule between my database data, and my Java data ?
For example, say my (badly designed) database stores string values of "YES" and "NO", which I'd like to convert to java boolean :

Code:

Table "SUBSCRIPTION":   
---------------------------------
|  ID   |   IS_MONTHLY
---------------------------------
|   1   |    'YES'         
|   2   |    'NO'         
|   3   |    'NO'         
---------------------------------

Java class:
@Entity public class Subscription {     
      @Id  private long id;     
      private boolean isMonthly;     // boolean
...
}


What is the recommended way to do the conversion ?
Thanks:)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 7:49 pm 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
Maybe this helps:
http://www.hibernate.org/189.html

Regards,
Pavol


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Tue Oct 02, 2007 7:42 am 
Beginner
Beginner

Joined: Tue May 11, 2004 12:20 am
Posts: 33
Just what i've been looking for - thank you very much!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 02, 2007 10:04 am 
Beginner
Beginner

Joined: Wed Jul 25, 2007 6:32 am
Posts: 22
I use a CustomBooleanType for this


Top
 Profile  
 
 Post subject: Thanks very much
PostPosted: Wed Oct 03, 2007 5:08 pm 
Beginner
Beginner

Joined: Tue May 11, 2004 12:20 am
Posts: 33
I'll try it out :)
thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.