-->
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.  [ 2 posts ] 
Author Message
 Post subject: Java 5.0 enum as "map-key"
PostPosted: Mon Jul 30, 2007 12:51 pm 
Newbie

Joined: Tue Jul 24, 2007 9:05 am
Posts: 2
Location: Paris, France
Hibernate version: 3.2.4

Hi all,

I am trying to use an enum type as map-key but cannot figure out how to do this.

I know how to map an enum using the GenericEnumUserType. Bu this does not work here because the <map-key> element does not allow an nested <type> element.

Do I have to persist the enum class in a separate table? If yes, how to achieve this using GenericEnumUserType? Or do I have to write a custom class.

Thanks for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 30, 2007 2:01 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Create a type for your Enum before the class definition and refer to this type in the map-key.
Code:
<hibernate-mapping package="test.mapwithusertypekey">

    <typedef name="map_key_enum_type" class="test.mapwithusertypekey.GenericEnumUserType">
        <param name="enumClass">test.mapwithusertypekey.MapKeyEnum</param>
    </typedef>

    <class name="Parent" table="mwutk_parent">
        <map name="valuesMap" table="values_map">
            <key column="parent_id"/>
            <map-key column="map_key" type="map_key_enum_type"/>
            <element column="map_value" type="string"/>
        </map>
...
    </class>


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