-->
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: Mapping a map collection with annotations
PostPosted: Wed Dec 01, 2010 12:52 pm 
Newbie

Joined: Mon Dec 25, 2006 4:59 am
Posts: 15
Hi guys
I need your help on mapping a map of objects with compound id using annotations
This is how am trying to do it.
Code:
class A
{
  ...
  @OneToMany()
  @JoinColumn(name="A_ID")
  /*   B_ID should be the key in this map */
  private Map<Long, B> map = new HashMap<Long, B>();
}

class B
{
  @EmbeddedId
  private CompoundId id;
}

@Embeddable
class CompoundId
{
  @Column(name = "A_ID")
  String aId;
 
  @Column(name = "B_ID")
  long bId
}


in mapping XML it looks like this

Code:
<map name="map" inverse="true" cascade="all-delete-orphan" lazy="false">
   <key>
      <column name="A_ID" />
   </key>

   <map-key type="long" column="B_ID"/>
   <one-to-many class="B" />
</map>


I am using hibernate 3.2.7.ga and annotations 3.4.0.GA

thx


Top
 Profile  
 
 Post subject: Re: Mapping a map collection with annotations
PostPosted: Mon Dec 06, 2010 8:08 am 
Newbie

Joined: Mon Dec 25, 2006 4:59 am
Posts: 15
The problem was in annotations of B class.

and I have annotated like this
Code:
@OneToMany(targetEntity = B.class , cascade = CascadeType.ALL , orphanRemoval = true , fetch = FetchType.EAGER)
@JoinColumn(name = "A_ID", referencedColumnName = "A_ID")
@MapKeyColumn(name = "B_ID")
private Map<Long, B> entities = new HashMap<Long, B>();


cheers


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.