-->
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.  [ 8 posts ] 
Author Message
 Post subject: How to persist enums
PostPosted: Thu Jun 03, 2004 10:50 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Hi,

Is there a clear answer to the question : what is the best way to persist enums.

I need to have a base class for my enums and I don't want to have one usertype class for each enum.

Browsing the site and the forum there is two differents possibilities :
- Use commons-lang valuedenum as shown at http://opensource.atlassian.com/project ... wse/HB-934
- Create my own persistentenum class that implements usertype. All my enums will extends this base class. There is a document on the wiki about that : http://www.hibernate.org/203.html

This solution seems very attractive for me as I need this base class for other purposes. Another benefit of this version is that I don't have to depends on commons-lang.

I just want Hibernate's team opinion about this implementation of enums. Is it something recommended or not ?

Thanx

Seb


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 11:27 am 
Regular
Regular

Joined: Wed May 12, 2004 3:03 am
Posts: 51
Location: France
I don't know if you knew it, I don't know if it will change something for you, but I just wanted to tell you that in jdk1.5.0 the type enum was implemented http://java.sun.com/developer/technicalArticles/releases/j2se15/

Maybe, it will be added soon to Hibernate...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 11:39 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
I've seen on some discussion in this forum that enum are not planned to be implemented soon.

seb


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 11:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
jdk 1.5 Enums will be supported in Hibernate3


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 11:59 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Is it possible to know if we have to create one UserType per enum or if jdk1.5 enums will be handled gracefully by hibernate without the need to create any other class

seb


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 12:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
It should be possible to use Enums just like any other natively supported type.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 18, 2004 8:53 am 
Newbie

Joined: Thu Dec 16, 2004 5:26 pm
Posts: 1
I'm trying to find out how to persist enums to a table.

As I have seen in dirrerent tutorials those enum records are static final variables of a usertype enum class. This data is not stored in any database table. I'd like my application to be able to add more records to this class on-the-fy. Solutions presented in tutorials would require modifying the source code of the usertype enum class.

I'd be nice if this data was kept in a separate table.

Hope it's understandable :-) Could anyone please describe a solution?

_________________
Regards,
PaSik


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 18, 2004 12:05 pm 
Regular
Regular

Joined: Thu Oct 07, 2004 4:45 pm
Posts: 92
What you're describing does not sound like an enum, which implies a compile-time value type (or a reference type that behaves like a value type).

If you want the elements to vary at run-time based on the contents of a database table, then you might want to consider modeling it as a regular entity with its own table and associations to other entities/tables. This requires no special support in Hibernate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.