-->
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.  [ 5 posts ] 
Author Message
 Post subject: Entities and Maps
PostPosted: Sun Sep 02, 2007 6:00 am 
Newbie

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

I'm having trouble getting an entity up and running. I have a "TextEntity" that has an id and a Language->String map, like this:

Code:
@Entity
public class TextEntity implements Serializable {
   @Id
   public Long getId() { ... }
   public Map<String, String> getTranslations() { ... }
}


When deploying, I'm getting the following error message:
javax.persistence.PersistenceException: org.hibernate.MappingException: Could not determine type for: java.util.Map, for columns: [org.hibernate.mapping.Column(translations)]

How can I accomplish this? I would like to keep it all in a single table, looking like this:

Code:
-----------------------------
| ID  |    LANGUAGE | VALUE |
|---------------------------|
|  1  |       en    |  Hi   |
|  1  |       sv    |  Hej  |
-----------------------------


So, in essence I have a composite primary key (ID, LANGUAGE), where the seccond element should be the key in the table.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 04, 2007 6:08 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

I think you are missing @MapKey annotation on the Map.

Cheers,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 10, 2007 3:31 am 
Newbie

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

I've tried setting the MapKey, but it doesn't make a difference w.r.t. the mapping failure. I need to be able to tell hibernate the key and value types.

Any ideas? Btw, this works with the traditional hibernate approach (XML mapping definitions) without any problems.

Regards,
Nille


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 10, 2007 7:55 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
just as an extra note, you have to be careful to put all your annotations at the same level i.e. all at veriable declaration, or all at getter level.

I have had the MappingException before with relationship mapping because of mixing where the annotations are.

Cheers,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 02, 2007 6:53 am 
Beginner
Beginner

Joined: Tue Jun 27, 2006 6:14 am
Posts: 24
Hi

Did you get this to work?

Thanks,
Chris


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