-->
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: Entity with java.util.Map question
PostPosted: Wed Jan 17, 2007 10:52 am 
Newbie

Joined: Wed Nov 29, 2006 9:35 am
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp


Hi @all

dont know if it is possible but i try the following:

-----------------------------------------------------------------------
db-schema:

table: week
attributes: id, namekey

table: day
attributes, id, namekey

n:m relation between week and day => n:m table: week_days

table: week_days
with attributes: id (week), id (day), dinner (string)

-----------------------------------------------------------------------

now i try the annotated class Dinner
@Entity
@Table (name="dinners", schema="hotelmenu")
public class Dinner {

private Week week;
private Map<Day, String> htlDinners;

@ManyToOne
@JoinColumn(name = "week_id")
public Week getWeek() {
return this.week;
}
+setter for week

@ManyToOne
@JoinColumn (name= "day_id")
@MapKey (name= "day_id")
@Column (name = "wd_dinner") //for String in Map
public Map<Day, String> getHtlDinners () {
return htlDinners;
}
+setter for htlDinners

+equals & hash
}

is it possible to map a java.util.Map like this or am i missing something?
btw. what is the @MapKey stand for?

cheers manakin


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 17, 2007 2:40 pm 
Beginner
Beginner

Joined: Wed Aug 24, 2005 5:32 am
Posts: 23
Hi Manakin,


You can map entities relations as a map. The MapKey annotation should hold
the
    1. Property of a mapped entity to be used as a key (the standard MapKey)
    2. Or, a joined column (Hibernate's MapKey)


You can read about Hibernate and maps here (on my blog): http://jroller.com/page/eyallupu?entry=hibernate_true_maps_support
and here: http://jroller.com/page/eyallupu?entry=using_annotations_to_persist_java

Eyal Lupu


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.