I have legacy code that I am trying to map to the new code.
OLD_PERSON
pid
sid
name
age
NEW_PERSON
pid
sid
fid
age
RESOLVE_PERSON
pid
fid
status
Java class
domain.Person {
ID _id;
String _name;
Integer _age;
}
In the legacy world, there was just one table: OLD_TABLE. The hibernate mapping was simple, just one class and its columns. In the new world, I have to use the above 3 tables and produce one Entity where the name comes from OLD_PERSON and age from NEW_PERSON. So basically a SQL query is:
select op.name as name, np.age as age
from OLD_PERSON op
INNER JOIN RESOLVE_PERSON rp
on rp.pid = op.pid
INNER JOIN NEW_PERSON np
on np.pid = rp.pid and np.fid = rp.fid and np.sid = op.sid
where rp.status = 'CURRENT'
Upon research/googling I found that I can use "Secondary tables" which are equivalent of "JOIN table" in hibernate xml. Note: I cannot use annotation as this code is old and I am still on hibernate3.5.6.
So I added a join table inside my mapping file:
<class name="domain.Person" table="OLD_PERSON">
<composite-id name="_id" class="Id">
<key-property access="property" name="key1" type="long" column="pid" />
<key-property access="property" name="key2" type="int" column="sid" />
<generator class="assigned" />
</composite-id>
<property name="_Name" type="String" column="name" />
<join table="NEW_PERSON" fetch="join" inverse="false">
<key>
<column name="pid" />
<column name="sid" />
</key>
<property name="_age" column="age" not-null="true" />
</join>
</class>
But the join to NEW_PERSON table requires an inner join with RESOLVE_PERSON table. I tried using subselect but its not the correct thing to use. I am unable to plug in formula anywhere here.
Any pointers on how this can be achieved? What I am essentially asking for is how to apply a criteria/constraint check on the JOIN.