-->
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: @MapKey - how to map properties from a different entity?
PostPosted: Fri Feb 15, 2008 6:34 pm 
Newbie

Joined: Fri Feb 15, 2008 6:24 pm
Posts: 5
Hi, I'm starting with Hibernate and I need some help with @MapKey.

I have this table in my database:

AVAILABILITY:
Code:
hour: integer (PK)
professor: integer (PK) (FK)
value: char.

Which is connected to table PROFESSOR (A professor has many availabilities).


I would like to have a Map<Integer, String> in the entity Professor, where the Integer is field 'hour' of AVAILABILITY and String is the field 'value'.

Is that possible?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 16, 2008 3:53 am 
Newbie

Joined: Wed Jan 16, 2008 2:53 am
Posts: 5
Hi
it's possible and in mapping you can use @CollectionOfElements


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 16, 2008 10:10 am 
Newbie

Joined: Fri Feb 15, 2008 6:24 pm
Posts: 5
Hmmm... that doesn't seem to be JPA...
Anyway, can you provide me an example? The usage isn't clear to me.


Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 16, 2008 5:48 pm 
Newbie

Joined: Fri Feb 15, 2008 6:24 pm
Posts: 5
After searching a lot, I found an example that suits me very well: https://i-proving.ca/space/Technologies ... f+Elements

So, the result is:
Code:
@CollectionOfElements
@JoinTable(name="availability", joinColumns=@JoinColumn(name="professor"))
@MapKey(columns={@Column(name="hour")})
@Column(name="value")
private Map<Integer, String> avail;


Thanks for your help.


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.