-->
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.  [ 3 posts ] 
Author Message
 Post subject: Can Hibernate map one table to multiple collections?
PostPosted: Wed Sep 01, 2004 6:55 am 
Newbie

Joined: Wed Sep 01, 2004 6:49 am
Posts: 2
Location: Milan, Italy
I am developing my first Hibernate application, which will be used to manage stores for a grocery chain.
The Store object owns a collection of items, called ExtraordinaryTimetable, representing extraordinary opening and closing hours on special days (e.g. holydays). The timetable objects are subject to a workflow, so they have a "status" property.
I first modeled this association with a Set in the Store class, and made the timetable object an entity for Hibernate. Then I changed my mind, and decided that it made more sense to map them as a component of Store. The idea is to have a Map of timetable items in the Store object, using the date as a key.

Here are some snippets of my java sources and mappings:

public class Store {
...
private Map extraordinaryTimetable;
...
}

public class ExtraordinaryTimetable {
...
private Date date;
private Date opening;
private Date closing;
private short status;
...
}

<hibernate-mapping>
<class name="...Store" table="TSTORE">
...
<map name="extraordinaryTimetable" table="TEXTTTB">
<key column="id_store"/>
<index column="DATE" type="date"/>
<composite-element class="...ExtraordinaryTimetable">
<property name="opening" type="time"/>
<property name="closing" type="time"/>
<property name="status"/>
...
</composite-element>
</map>
...
</class>
</hibernate-mapping>

Now, here's the problem and my question.
The workflow allows more than one timetable item to have the same date, if they have a different status (items with the same status must have different dates).
Therefore I need to have separate Map's in the Store class for each status, but at the same time I would like to keep all items in the same database table.
Is there a way to have Hibernate populate my maps using the status column as a discriminator, much like it does when dealing with subclasses?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 12:58 pm 
Beginner
Beginner

Joined: Mon May 03, 2004 1:25 pm
Posts: 31
I think that you could put a "where clause" on the set.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 7:45 am 
Newbie

Joined: Wed Sep 01, 2004 6:49 am
Posts: 2
Location: Milan, Italy
Thanks, I'll try that.


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