-->
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.  [ 1 post ] 
Author Message
 Post subject: How to annotate an EnumMap with an Enum as a value?
PostPosted: Tue Apr 02, 2013 12:52 pm 
Newbie

Joined: Tue Apr 02, 2013 12:47 pm
Posts: 1
I'm using Hibernate annotations in a class containing a map of properties, which are basically <name, value> pairs. The property names are defined in a PROPERTY enum, and each property has a set of permissible values, also defined as an enum. Since each property has its own enum defined for its values, the property map is defined as

Code:
Map<PROPERTY, Enum> properties = new EnumMap<PROPERTY, Enum> (PROPERTY.class);

I am having trouble mapping the Enum value. This definition:

Code:
@ElementCollection
@MapKeyEnumerated(EnumType.STRING)
@MapKeyColumn(name="name")
@Column(name="value")
@Enumerated(EnumType.STRING)
Map<PROPERTY, Enum> properties = new EnumMap<PROPERTY, Enum> (PROPERTY.class);

generates the following DDL:

Code:
create table EnumMapTest (
    id bigint not null auto_increment,
    primary key (id)
) ENGINE=InnoDB;

create table EnumMapTest_properties (
    EnumMapTest_id bigint not null,
    value tinyblob,
    name varchar(255) not null,
    primary key (EnumMapTest_id, name)
) ENGINE=InnoDB;

As you can see, the Enum class is mapped as a tinyblob, which is totally unreadable in the database.

If I define the map with a concrete enum

Code:
@ElementCollection
@MapKeyEnumerated(EnumType.STRING)
@MapKeyColumn(name="name")
@Column(name="value")
@Enumerated(EnumType.STRING)
Map<PROPERTY, VALUE> properties = new EnumMap<PROPERTY, VALUE> (PROPERTY.class);

the mapping is fine:

Code:
create table EnumMapTest_properties (
    EnumMapTest_id bigint not null,
    value varchar(255),
    name varchar(255) not null,
    primary key (EnumMapTest_id, name)
) ENGINE=InnoDB;

So the issue is the mapping of the Enum class itself.

Is there a way to do map an Enum to something readable (preferably a string) without creating a custom type?

I hope the fact that we are still at Hibernate 3.6.10 won't be held against us.

TIA for any assistance


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.