-->
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.  [ 5 posts ] 
Author Message
 Post subject: Property discriminator for many-to-many relationship
PostPosted: Thu Dec 07, 2006 3:17 am 
Newbie

Joined: Thu Dec 07, 2006 3:03 am
Posts: 1
I have a parent object that can have two different types of children (call them Red children and Blue children). My object model looks something like the following:

Code:
public class Parent {
   public long getId();
   public void setId();

   public List getRedChildren();
   public void setRedChildren(List c);

   public List getBlueChildren();
   public void setBlueChildren(List c);

   // ...
};

public class Child {
   public long getId();
   public void setId(long n);

   // ...
};


Underneath, these object model needs to map onto the following table structure:

Code:
CREATE TABLE Parent(
  id NUMBER(14) NOT NULL PRIMARY KEY,
  ...
);

CREATE TABLE Child(
  id NUMBER(14) NOT NULL PRIMARY KEY
  ...
);

CREATE TABLE ParentChildMap(
   parent_id NUMBER(14),
   child_id NUMBER(14),
   child_type VARCHAR(1)
);


where the child_type column on ParentChildMap determines whether the child is blue or red ('B' for blue, 'R' for red). I'm trying to create a read/write mapping for this object model on to this table model. I know I can use a where clause on my many-to-many mapping for redChildren and blueChildren to only select the rows that have the appropriate child_type. But I'm trying to make this a read/write mapping, such that when I persist a parent that contains Red children, an entry is created in the ParentChildMap table with the appropriate child_type value. I've gone through the docs and the forums, but haven't found a way to achieve this. Can this be accomplished through the mapping file?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 8:39 pm 
Senior
Senior

Joined: Sat Nov 27, 2004 4:13 am
Posts: 137
define two different classes (BlueChild and RedChild) which extend the Child with a discriminator column, and well everything is done.

_________________
don't forget to credit!

Amir Pashazadeh
Payeshgaran MT
پايشگران مديريت طرح
http://www.payeshgaran.co
http://www.payeshgaran.org
http://www.payeshgaran.net


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 6:39 am 
Newbie

Joined: Sat Dec 16, 2006 6:31 am
Posts: 3
I have the same problem.

However, the proposed solution is not good, because the same child may be red or blue depending on the parent, so extending child with a discriminator column is not a good solution.

Anybody else?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 9:28 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
ambro23 wrote:
However, the proposed solution is not good, because the same child may be red or blue depending on the parent, so extending child with a discriminator column is not a good solution.

What do you mean? You want to change the child type at runtime, that's to say ? The delta between the good solution adviced and your requirement is not very clear.

Also Maybe open a new post to discuss your subject.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 11:40 am 
Newbie

Joined: Sat Dec 16, 2006 6:31 am
Posts: 3
batmat wrote:
Also Maybe open a new post to discuss your subject.


Ok, new topic is created. Please come to:

http://forum.hibernate.org/viewtopic.php?t=968714


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.