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.
|