posted 12 years ago
Hi,
I want to create a relationship on one table with multiple tables based on value in another column. How can I do that in hibernate.
eg:
Rejections table has two columns ref_id and ref_type and based on the value of ref_type, it will look for in different tables. if ref_type is "soft" it will look into softwares table for ref_id, if ref_type is "service" it will look into services table for same ref_id.
basically table A has one reference column and on reference type column (descriptor column). Table A joins to Table B, Table C and Table D on same reference columns but based on descriptor column value. Table B/C/D all are distinct entities of different type and have no relation logically and domain wise. Item created by Table A will have has a relationship with these tables. I want to fetch Table A records based on some joins which can join A with any of B/C/D.
its like
select * from (
select A.* from table A,table B where A.reference=B.id and B.somecolumn='abcdefg'
UNIOIN
select A.* from table A,table C where A.reference=C.id and C.somecolumn='xyz')
order by 1