-->
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: conditional relationship mapping
PostPosted: Thu Aug 28, 2008 5:08 am 
Newbie

Joined: Thu Aug 28, 2008 4:34 am
Posts: 1
I am using hibernate annotations and want to map a relationship on a legacy database. I have an Account table and a Person table with a ManyToMany relationship between them defined by a Role table.

One of the Persons attached each account is specified as the primary owner and this is indicated by a flag on the Role table. Ideally this would be a foreign key from account to person and I could map a direct relationship using @ManyToOne from account to person but I am not at liberty to change the schema.

Is there a way I can map a ManyToOne relationship through the join table such that account.getPrimaryPerson() would return me the Person joined to this account by the Role where role.primaryFlag is true. There is only ever one Role attached to an account with this flag set.

I know how to get the primary person for a given account in HQL or using criteria but I would like to make it a method on the account and preferrable lazily loaded.

Regards
PSjoberg


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.