-->
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: Use a Java5 enum as @Embeddable
PostPosted: Wed Jan 21, 2009 11:55 am 
Newbie

Joined: Mon Jan 29, 2007 9:50 am
Posts: 7
Hi,

I need to store some enum in database, but can't use either the ordinal nor the enum "constant" name. I need to use a value passed to the enum in constructor that is used internally :

public enum Acte
{
ACHAT( 10 ),
ACTIVATION( 2 ),
ANNULATION( 8 )
...
}

I'd like to use such enum class as JPA @Embeddable.
Is this possible ? Maybe there is some
Hibernate non-JPA support for such use case ?

Thanks for any suggestion.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2009 4:05 am 
Newbie

Joined: Mon Jan 29, 2007 9:50 am
Posts: 7
As a side note, the question could be :
"is there any way to define a global Type Converter in Hibernate ?"

I'd like to avoid to annotate all my enums with a @Type.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2009 4:20 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
How about converting the internal value in your entity:
Code:
@Entity
public class YourEntity {
   ...
   //avoid that hibernate stores the enum
   @Transient
   public Acte getActe(){...}
   ...
   //private getter, only used by hibernate
   private Integer getActeInternal(){
     //return the inner value here
   }
   
   private void setActeInternal() {
     // do your conversion here
   }
}

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2009 4:57 am 
Newbie

Joined: Mon Jan 29, 2007 9:50 am
Posts: 7
It's even more intrusing than some @Type annotation

@Type seems to be the simpliest solution in my case


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.