-->
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: One-to-One Annotation Mapping w/ predefined column data
PostPosted: Wed Feb 22, 2012 5:36 am 
Newbie

Joined: Wed Feb 22, 2012 5:08 am
Posts: 1
First, a simplified version of the database:

Table A: (type = 1)
-id

Table B: (type = 2)
-id

Table C: (type = 3)
-id

Table Z:
-id
-type_id
-fk_id

I have multiple tables that need to access one table based on their type (an Integer value). Table A, B, and C, will always have one and only one table Z association and that association is defined by matching the id of table A, B, or C to the fk_id and matching type_id in table Z. Ideally, I would prefer to not include the Table Z id in A, B, or C, and I would also not like individual columns for type_ids in A, B, and C.

Sample Data:

Table A: (Type = 1)
id
1
2

Table B: (Type = 2)
id
1

Table C: (type = 3)
id
1
2

Table C:
id type_id fk_id
1 1 1
2 1 2
3 2 1
4 3 1
5 3 2

I've tried adding @Where, @Filter, @Formula, etc onto the @OneToOne relationship with no avail. Is this type of association even possible in annotations, or will I need to use HQL?

Example of what would be ideal (if the where annotation actually worked in one to one relationships) :

Table Z
@OneToOne(targetEntity=A.class)
@JoinColumn(name="fk_id", referencedColumnName="id")
@Where(clause="type_id=3")
private A a;

Table A
@OneToOne(mappedBy="a", targetEntity=Z.class)
private Z z;

Any advice would be greatly appreciated, thanks.

EDIT: I apologize that my formatting did not work very well for the example data.


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.