-->
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.  [ 1 post ] 
Author Message
 Post subject: Redundant 1:n mapping possible?
PostPosted: Mon Mar 12, 2007 9:50 am 
Newbie

Joined: Mon Oct 10, 2005 6:10 am
Posts: 10
Hi,

is there a way to have a one-to-many (e.g.) relationship more than once in a mapping?

The example below illustrates that I'd like to have two distinct collections each referencing the same class "Child" but collection maleChildren contains only a subset (as collection femalChildren does) of all 1:n children.

As I'd like to alter and persist both collections, a read-only mapping of one collection is not a solution.

The mapping in this example is not allowed and causes an exception.

Any ideas, hints are welcome!

//PSEUDOCODE


Tables:

PARENT (ID,NAME)
CHILDREN(ID,PARENT_ID,GENDER,NAME)

class Parent {

@Id
int id;

String name;

//
@OneToMany(mappedBy = "parent")
@Where("gender=0") ???
Collection<Child> maleChildren;

//second mapping is not allowed - any alternatives?
@OneToMany(mappedBy = "parent")
@Where("gender=1") ???
Collection<Child> femaleChildren

}

class Child{

static MALE_CHILD = 0;
static FEMALE_CHILD = 1;

int gender = 0;

@ID
int id;

@ManyToOne
@JoinColumn(name="parent_id",nullable=false)
Parent parent;

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.