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.  [ 3 posts ] 
Author Message
 Post subject: JPA - Map<String, String>
PostPosted: Mon Feb 04, 2008 6:37 pm 
Newbie

Joined: Sun Sep 02, 2007 5:45 am
Posts: 4
Hi!

Is it possible to map a Map<String, String> to a secondary table using Hibernate Annotations? For example:

Code:
@Entity
public class Text
{

   @Id
   private Long id;

   @SecondaryTable(???)
   private Map<String, String> translations;

   public Long getId() { ... }
   public Map<String, String> getTranslations() { ... }

}


The idea is to allow e.g.

Code:
Text text = myTextDAO.get(myTextId);

// Get a translation
String english = text.getTranslations().get(Locale.ENGLISH.getLanguage());

// Add a translation
text.getTranslations().put("sv", "Hej");


The secondary table would concist of TEXT_ID, LANGUAGE_ID, TRANSLATION with (TEXT_ID, LANGUAGE_ID) as primary key.

I know it's possible to map string -> entity, but that's not what I'm looking for right now. I think this is possible with an XML configuration as well, but I haven't figured it out in JPA.

Regards,
Nille


Top
 Profile  
 
 Post subject: Re: JPA - Map<String, String>
PostPosted: Mon Feb 04, 2008 6:48 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
I guess you will have to hibernate's annotation CollectionOfElements. I am not sure if this is supported in JPA at all but you can mix JPA with hibernate annotations.



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 04, 2008 6:57 pm 
Newbie

Joined: Sun Sep 02, 2007 5:45 am
Posts: 4
Thanks! That'll work for now.

Regards,
Nille


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