-->
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: foreign key points to different column dynamically
PostPosted: Fri Aug 19, 2016 8:46 pm 
Newbie

Joined: Tue Aug 05, 2008 3:11 pm
Posts: 7
Legacy database 2 tables:
table A (a materialized view): col-a1, col-a2, ...
table B: id, col-b1, ...

Question:
col-b1 contains combined values of col-a1 and col-a2
for some rows, col-b1's values reference to col-a1; for other rows, col-b1's values reference to col-a2

How should I do hibernate entity mapping with annonation? I need col-a1 be primary key sometime to join col-b1, and col-a2 be primary other times to join col-b1. Is it possible?

I don't want to create 2 sets of entities (i.e Entity_A1, col-a1 PK --> Entity_B1; Entity_A2 col-a2 PK --> Entity_B2)
thanks


Top
 Profile  
 
 Post subject: Re: foreign key points to different column dynamically
PostPosted: Mon Aug 29, 2016 4:16 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Try using @JoinColumnOrFormula as indicated in this StackOverflow answer.


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.