-->
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.  [ 2 posts ] 
Author Message
 Post subject: how to map an array inside a map?
PostPosted: Mon Mar 01, 2010 2:55 pm 
Regular
Regular

Joined: Fri May 22, 2009 4:50 am
Posts: 59
Hi,

I am having difficulty in mapping an array inside a map.
I have a Class A which has a map of Class B and Class B contains an array.

Class A {
private HashMap<string, B> map = new HashMap<string, B>
}

where

Class B {
private int[] bs;
}

I managed to do a hack but i wanted to know the optimal way it is done in hibernate.

Any ideas and help is appreciated..
Thanks


Top
 Profile  
 
 Post subject: Re: how to map an array inside a map?
PostPosted: Wed Mar 03, 2010 11:20 am 
Beginner
Beginner

Joined: Tue Aug 25, 2009 11:42 am
Posts: 49
Code:
public class A {
   int id;
   Map<String, B> b;
}
public class B {
   int id;
   int[] vals;
}
   <class name="A">
      <id name="id" access="field">
         <generator class="native" />
      </id>
      <map name="b" access="field" cascade="all-delete-orphan">
         <key />
         <map-key type="string" />
         <one-to-many class="B" /> <!-- maybe ur usecase may be different and u want many-to-many -->
      </map>
   </class>
   <class name="B">
      <id name="id" access="field">
         <generator class="native" />
      </id>
      <array name="vals" access="field">
         <key />
         <list-index />
         <element type="int"/>
      </array>
   </class>


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