-->
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: How would I map a List collection stored within Map values
PostPosted: Fri Oct 03, 2008 1:48 pm 
Newbie

Joined: Mon Sep 22, 2008 9:31 am
Posts: 9
Hibernate version: 3.2.5

How would I map the following Map<EnumA, List<ClassB>>???

I may be way off, but, currently I have something like the following.

Code:
<class...>
...
<map name="myMap" table="tbl_for_map" collection-type="my.special.collection.type.MyCollectionType">
  <key column="key_from_above"/>
  <index column="myMapKey" type="my.special.user.type.for.EnumAUserType"/>
  <one-to-many class="my.ClassB"/>
</map>
</class>


Now the error that I receive is pretty obvious:
Code:
HibernateException: instance not of expected entity type: "java.util.List" is not a: "my.ClassB"


However, I can't seem to find any mapping element that will allow me to specify that the value of the map is a java.util.List that holds numerous my.ClassB objects (instead of using the one-to-many with a class attribute of my.ClassB).

Any help or direction would be greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 9:32 am 
Newbie

Joined: Mon Sep 22, 2008 9:31 am
Posts: 9
Any ideas???? Or is this not possible? Any help would be greatly appreciated.


Top
 Profile  
 
 Post subject: You may want to try something like this.
PostPosted: Wed Oct 08, 2008 11:04 am 
Newbie

Joined: Wed Oct 08, 2008 10:56 am
Posts: 1
I tried something very similar and could not make it work. I had to create a separate class to contain the list of entities. Here are the details.
Java
private Map<MetadataString, ParentFieldAssociations> fieldAssociations = new HashMap<MetadataString,ParentFieldAssociations>();

Mappings
<class name="collective.asset.ParentFieldAssociations" table="ParentFieldAssociations">
<id name="id" unsaved-value="null">
<generator class="native" />
</id>
<list name="fields" table="ParentFieldsList">
<key column="parentFieldId"/>
<list-index column="idx"/>
<many-to-many class="collective.asset.AbstractMetadataField"/>
</list>
</class>


<class name="collective.asset.ParentPropertySelectionField" discriminator-value="ParentProperySelectionField">
<map name="fieldAssociations" table="ParentMetadataFieldsMap">
<key column="id" />
<map-key-many-to-many column="stringId" class="collective.asset.MetadataString"/>
<many-to-many column="fieldAssociationId" class="collective.asset.ParentFieldAssociations"/>
</map>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2008 4:27 pm 
Newbie

Joined: Mon Sep 22, 2008 9:31 am
Posts: 9
Dkallstrom, thank you for your post. I was afraid that was going to be the answer. I just don't quite understand why Hibernate does not allow for mapping nested collections (e.g. Map<String, List<String>> or the like); However, that intended functionality is available to you by simply wrapping the nested Collection in some type of "middleman" object that contains your Collection. It just doesn't quite add up. Maybe it will be addressed at a later time (or am I the only one wanting/needing to do this?) Thanks again for your post and assistance.


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.