-->
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.  [ 7 posts ] 
Author Message
 Post subject: Java 5 Enum mapping in hbm
PostPosted: Fri Oct 13, 2006 11:18 am 
Beginner
Beginner

Joined: Fri Oct 06, 2006 2:49 am
Posts: 25
I would like to translate the annotations of this portion of code in hbm

public abstract class myObject<E extends Enum>
{

@Enumerated(EnumType.STRING)
@Column(length = 30)
@Length(min = 1, max = 30)
@NotNull
private E myField;

...

}

I have try this:

<property name="myfield" length="30">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">java.lang.Enum</param>
</type>
</property>

but I get an error...

Does anyone have a solution for this ?

Thanks in advance,
tiggy


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 4:54 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
E needs to be resolved to a specific type, not java.lang.Enum

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 11:51 am 
Newbie

Joined: Thu Dec 29, 2005 8:42 pm
Posts: 8
I've been seacrhing for a way to map enums to varchar columns for a long time usinh .hbm files. This post gave me the clue I needed, so for everyone looking for this solution. This is how you modify the mapping above to map to varchars:

<property name="myfield" length="30">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">org.judge.myenum</param>
<param name="type">12</param>
</type>
</property>

The number 12 is one of the constants from java.sql.Types.


Top
 Profile  
 
 Post subject: Explanation needed for EnumType usage
PostPosted: Mon Feb 18, 2008 10:12 am 
Newbie

Joined: Mon Feb 18, 2008 10:09 am
Posts: 1
Location: Israel
judge wrote:
I've been seacrhing for a way to map enums to varchar columns for a long time usinh .hbm files. This post gave me the clue I needed, so for everyone looking for this solution. This is how you modify the mapping above to map to varchars:

<property name="myfield" length="30">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">org.judge.myenum</param>
<param name="type">12</param>
</type>
</property>

The number 12 is one of the constants from java.sql.Types.


Can anyone provide a good explanation regarding the usage of EnumType: The parameters needed and their meaning. For example: Why hardcoding 12?

I couldn't any good explanation while Googling.

Asaf


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 19, 2008 8:24 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
As said above, this is the constant value in java.sql.Types. Ain't gonna change

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 09, 2008 3:44 am 
Newbie

Joined: Sun Feb 24, 2008 5:12 pm
Posts: 9
And how to do it for a java.util.Map where enum is the key(index)?

Regards


Top
 Profile  
 
 Post subject: Re: Java 5 Enum mapping in hbm
PostPosted: Thu Oct 01, 2009 4:25 am 
Newbie

Joined: Fri Aug 14, 2009 8:06 am
Posts: 19
I would also like to know how to save maps in Hibernate where the key is an enum, doing this with a .hbm file, not with annotations.

Cheers,
Stef


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