-->
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: using a map<String, String> without a separate entity
PostPosted: Thu Jul 24, 2008 12:06 pm 
Newbie

Joined: Fri Jul 18, 2008 6:48 am
Posts: 5
hi there,

i've read through the annotations and normal documentation, so forgive me if this is a silly question, but i couldn't find an answer.

basically, i have a user object that is working fine, what i'd like to do is add a Map<String, String> called profile to the user object.

is there any way (using annotations) to get hibernate to generate a table called 'user_profile' which has 3 columns, user, key, and value, and map these columns to the key/value pairs of the Map<String, String>? it would be a one-to-many mapping, because a user can have an arbitrary number of profile settings defined, but there is a constraint that a user can only have 1 profile setting for a given key (which is worked out nicely by the map)

any ideas?

thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 25, 2008 6:44 am 
Newbie

Joined: Fri Jul 25, 2008 6:19 am
Posts: 1
this solution works for me!

Code:
@CollectionOfElements
@JoinTable(name = "user_profile",
      joinColumns = { @JoinColumn(name = "id") })
@org.hibernate.annotations.MapKey(
      columns = { @Column(name = "`key`") })
               @Column(name = "`value`",length=131070,nullable = false)
public Map<String, String> getMap() {
   return map;
}


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.