java - Join different tables determined by a control filed -


there 3 tables , b1 , b2:

a(id, b_id, control) b1(id, other) b2(id, other)  if control = 1, b_id in mapping table b1; if control = 2, b_id in mapping table b2. 

these 3 classes like:

@entity @table(name = "a") public class {     @id     @column(name = "id")     private integer id;      private b b;      @column(name = "control")     private integer control; }   @entity @table(name = "b1") public class b1 {     @id     @column(name = "id")     private integer id;      @column(name = "other")     private integer other; } 

class b2 same b1.

i need different object b table b1 or b2 determined field control in class a. possible make hibernate annotation?

appreciated advice.

i think missing out way 1 table refers in sql. mean way have defined tables there no foreign keys , no referential integrity secured. recommend reconsidering implementation , add respective foreign keys in table.

anyway, if want continue this, should check out union statement in sql.

select a.id, b1.others   inner join b1  on a.control = 1 , a.b_id= b1.id union select a.id, b2.others   inner join b2  on a.control = 2 , a.b_id= b2.id 

now have noticed there problem in hql union statement (not supported think?) there possible other implementations.

also notice have select same columns in order union 2 subqueries.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -