-->
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.  [ 6 posts ] 
Author Message
 Post subject: Mapping the composition of two domain objects to a scalar
PostPosted: Mon Nov 03, 2003 1:49 pm 
Beginner
Beginner

Joined: Wed Oct 15, 2003 3:08 pm
Posts: 32
I need to create a table that is similar to a many-to-many mapping for "resources" and "systems". Each resource will be mapped to 0 or more systems on which it can run. Each system will be mapped to 0 or more resources that are configured to run on it.

The twist to this is that I would like to map the state of each resource on each system. So, I want a table like this:

Code:
resource_id, system_id, state


State is a UserType, not sure if that will matter much or not. Anyway, I've been looking at ternary maps, but they do not seem to be exactly what I want. They want to add another column (idx), I guess because they think there could be multiple states for the resource/system pair.

Should I just make a domain object that represents this map? What is the best practice for this type of mapping?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 03, 2003 2:01 pm 
Beginner
Beginner

Joined: Wed Oct 15, 2003 3:08 pm
Posts: 32
One other key point, which I neglected, is that I want to do this with one table. The ternary mapping seems to need two tables to pull this off, but I don't want to maintain two separate tables.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 03, 2003 2:33 pm 
Beginner
Beginner

Joined: Wed Oct 15, 2003 3:08 pm
Posts: 32
Looks like this is in the FAQ: http://www.hibernate.org/118.html#A10.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 03, 2003 3:26 pm 
Beginner
Beginner

Joined: Wed Oct 15, 2003 3:08 pm
Posts: 32
Ok, the composite elements solution looked good until I read the fine print, which says, "properties of composite elements cannot be used in a query." With the example table I gave above it sounds like I can't ask the following question:

Quote:
Which systems have resource x that is in state y


This sounds like a pretty severe limitation. In SQL I could to this as:

Quote:
SELECT system_id FROM resource_system_state WHERE resource_id='x' AND state='y'


I'm sure there is a good reason why Hibernate can't do this, but is there a work around for this situation?

What I'd like is a table that has these three columns (resource_id, system_id, state) and that I can query on any column or combination of columns.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 03, 2003 4:39 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I think it's doable since Hibernate 2.1beta1.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 3:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
composite elements may be queried in 2.1


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