-->
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.  [ 7 posts ] 
Author Message
 Post subject: 'Map' mapping - please help me, I'm lost.
PostPosted: Wed Feb 08, 2006 6:29 pm 
Newbie

Joined: Tue May 10, 2005 1:19 pm
Posts: 10
Hi All

I'm using hibernate 3.1.2 and annotations 3.1 beta 8.

I'm stuck trying to figure out haw to map a Map of core types e.g.

public Map<String,String> getMyData();

As I understand it, the EJB3 annotations don't support mapping of core types, so I'm not surprised that @OneToMany fails.

According to http://www.hibernate.org/hib_docs/annot ... e/#d0e2065 the hibernate extensions do support collections of core types, using @CollectionOfElements.

I can't make this work for a Map rather than a Set. Is @CollectionOfElements supported for Maps and if so, please could someone provide an example? Right now I'm getting an error ('A Map must declare a @MapKey element') but I can't figure out how to get round it. Adding a @MapKey element is tricky when their is no name to map to!

Thanks

Jonathan.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 9:47 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
@MapKey does not make any sense for collection of core types.
support for true maps is not implemented yet (ANN-1)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 2:56 pm 
Newbie

Joined: Tue May 10, 2005 1:19 pm
Posts: 10
Ahh, OK thanks. Guess I'll kick back and wait for beta9 then :-)

Jonathan.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 10, 2006 7:07 pm 
Newbie

Joined: Tue Oct 10, 2006 6:42 pm
Posts: 5
I'm currently struggling with this. Would greatly appreciate a pointer to a definitive example re: using annotations to support a Map<String, String>. I've now been through several books, the annotation docs, and this forum. No luck. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 8:32 am 
Newbie

Joined: Tue May 10, 2005 1:19 pm
Posts: 10
As I discovered recently, the tests are a good source of examples, often more so than the documentation. The following extract from
test/org/hibernate/test/annotations/collectionelement/Boy.java is close to what you need I think:

@CollectionOfElements
@JoinTable(name = "ScorePerNickName", joinColumns = @JoinColumn(name = "BoyId"))
@Column(name = "score", nullable = false)
public Map<String, Integer> getScorePerNickName() {
return scorePerNickName;
}


Hope this helps

Jonathan.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 8:49 am 
Newbie

Joined: Tue Oct 10, 2006 6:42 pm
Posts: 5
Actually got this to work last night, but something seems amiss.

I had to do the following...

@MapKey(columns=@Column(name="mapkey"))
public Map <String, String>getProps()
{
return props;
}

...to force the column name output by the hbm2dll schema generation to use the same column name as the hibernate runtime. Otherwise the session operations would fail as the column names did not match.

Is this a bug that should be filed? I just double checked the installed tools. I'm using Tools 3.2.0.beta7, Annotations 3.2.0.CR2, and Hibernate 3.2.0.CR4. But hbm2dll is reporting tools version CR1.

?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 11:19 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you mean a mismatch between the tools and HAN CR2?
This is expected, the versions are not synchronized. This will be fixed with the next version of Tools

_________________
Emmanuel


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