-->
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: [Solved] Hibernate Annotations @MapKey
PostPosted: Tue Mar 03, 2009 7:48 am 
Newbie

Joined: Tue Dec 05, 2006 3:00 am
Posts: 15
Please Observe below scenario

Code:
Class Responsible{
.....

@MapKey(name = "addressType")
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "responsible")
protected Map<String, ContactAddress> addresses = new HashMap<String, ContactAddress>();

.....
}


Code:
Class ContactAddress {
.....

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "typeId", unique = true)
protected AddressType addressType = new AddressType();

.....
}


Code:
Class AddressType {
.....

   @Id
   @GeneratedValue(strategy = IDENTITY)
   @Column(name = "typeId", unique = true, nullable = false)
   protected Long            typeId;

.....
}



When Responsible record fetched then the addresses(MAP) is loading with AddressType as key and ContactAddress as values in MAP. But I need AddressType.typeId as key in that MAP.

How can I get that typeId as key in addresses MAP?


Thanks
Ram


Last edited by bcaramu on Fri Mar 06, 2009 7:09 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 03, 2009 8:51 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Have you tried @MapKey("addressType.typeId")?

Btw typeId is a Long but you define your Map as Map<String, ContactAddress>

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 03, 2009 9:26 am 
Newbie

Joined: Tue Dec 05, 2006 3:00 am
Posts: 15
Thanks for your Reply

I tried with below

Code:
@MapKey(name = "addressType.typeId")
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "responsible")
protected Map<String, ContactAddress>      addresses            = new HashMap<String, ContactAddress>();



But no use got error like

Caused by: org.hibernate.AnnotationException: Map key property not found: com.cmc.model.ContactAddress.addressType.typeId


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 06, 2009 4:58 am 
Newbie

Joined: Tue Dec 05, 2006 3:00 am
Posts: 15
Solved with Hibernate MapKey instead of JPA.

Code:
@MapKey(columns=@Column(name="typeId"))


Thanks for Your support.


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.