-->
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.  [ 2 posts ] 
Author Message
 Post subject: OneToOne, but based on a second column, is it possible?
PostPosted: Thu Feb 22, 2007 10:37 am 
Newbie

Joined: Fri Jan 26, 2007 9:58 am
Posts: 18
Location: Dublin
Hibernate version: 3.2.2

Hopefully a simple example to show what I mean:

A HousePurchaseTransaction has a buyer and a seller (both instances of TransactionOwner), if we wanted to capture that relationship it would be normal to link buyer and seller PK in HousePurchaseTransaction, but this is not done, instead the TransactionOwner class has a relation to the HousePurchaseTransaction, and another column holds a ownerType flag to indicate whether they were the purchaser or the seller:

HousePurchaseTransaction
number hptPk (oracle seq generated)
xxx other data

TransactionOwner
number toPk(oracle seq generated)
number hptPk (foreign key to above)
string ownerType (either buyer or seller)

All works fine when saving the data but come to reload time (call read on the HousePurchaseTransaction) how can it differentiate between the two owners, on the 'one to one's both say:

@OneToOne (mappedBy = "houseTransactionOwner)
getBuyer();

@OneToOne (mappedBy = "houseTransactionOwner)
getSeller();

I need to put a second join column in here, something like


@OneToOne (mappedBy = "houseTransactionOwner, where = "ownerType = 'Seller'")
getSeller();

Anyone have any idea how this might be possible?

Thanks, (points will be awarded)

Chris.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 23, 2007 12:49 pm 
Newbie

Joined: Fri Jan 26, 2007 9:58 am
Posts: 18
Location: Dublin
Seems after more investigation that the answer is to upgrade to JPA/Entity Manager and override the annotation mapping in an xml file and assign it using a formula, as formulas aren't supported in annotations on join columns yet.


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