-->
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.  [ 4 posts ] 
Author Message
 Post subject: Map<Entity1, SortedSet<Entity2>>
PostPosted: Fri Jun 16, 2006 8:52 pm 
Newbie

Joined: Thu Jun 15, 2006 3:33 pm
Posts: 11
Location: Bristol, England
The business of mapping a Map is very confusing.

The docs and FAQ (http://www.hibernate.org/329.html#A12) state that Map isn't fully supported, but "Hibernate Annotations does support Hibernate style Map mapping (ie explcit column for the map key) for Map<Element, ...> and Map<Embeddable, ...> (support for Map<Entity, ...> is expected later)".

However, looking at the changelog for my version of hibernate-annotations - 3.2.0.CR1 - there are a number of issues that have been recently been fixed in this area, e.g.

* Support for Map<Entity, Entity> - http://opensource.atlassian.com/project ... se/ANN-327
* http://opensource.atlassian.com/project ... se/ANN-281

The question is, is it now possible to easily persist the Map in this getter:

Code:
public Map<MyClassA, SortedSet<MyClassB>> getMyMap() {
  return this.myMap;
}


with annotations? If so, how? Please provide as full as code as possible if you can, I only started learning hibernate yesterday :-)

Oliver


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 1:55 am 
Newbie

Joined: Thu Jun 15, 2006 3:33 pm
Posts: 11
Location: Bristol, England
Is it actually possible to map this directly or would you have to do something else like
Code:
public Map<MyClassA, SortedSetMyClassB> getMyMap() {
  return this.myMap;
}


where

Code:
@Entity
public class SortedSetMyClassB {

@OneToMany
@Sort(type=SortType.NATURAL)
public SortedSet<MyClassB> getSortedSet() {
  return this.sortedSet;
}

private SortedSet<MyClassB> = new HashSet<MyClassB>();

// + id property and other necessary setter & getters for the class

}


If so, how would you annotate that Map?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 4:59 pm 
Newbie

Joined: Thu Jun 22, 2006 6:35 am
Posts: 5
Hi Oliver,

according to the forum topic
http://forum.hibernate.org/viewtopic.php?t=956662&highlight=map+entity
Quote:
Collection of collections are not supported by Hibernate

As I would call Map<MyClassA, SortedSet<MyClassB>> a "Collection of collections", you will most likely have to realize your SortedSetMyClassB, i.e. encapsulate the set in an entity.

As for the question of the proper annotation for the map, I would suggest just using
Code:
@ManyToMany(cascade = CascadeType.ALL)

In absence of javax.persistence.MapKey, Hibernate will automatically offer real map support. If you need to override the default column for the map-key, you can add something like
Code:
@MapKeyManyToMany(joinColumns = @JoinColumn(name = "key_id"))


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 3:56 am 
Newbie

Joined: Thu Jun 15, 2006 3:33 pm
Posts: 11
Location: Bristol, England
Thanks, I've extended Java's SortedSet to make my own SortedSetMyClassB and it seems to work.


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