I'm working with a legacy database and I'm trying to get hibernate to help me.
I have 3 tables that look something like:
Table results:
id (number pk)
info_id (varchar)
result (varchar)
Table info
id (number pk)
info_id (varchar)
Table registration
id (number pk)
Table letter
id (number pk)
registration_id
I'm only able to modify the Object for letter, and in this object I want to be able to get a (read only) list of results
public class Letter {
private Long id;
private Registration registration;
private List<Result> results;
}
The registration object already exists, and looks like this:
public class Registration {
private Long id;
private Info info;
}
I'm trying to map the results object to the Letter object , and I was attempting something like this:
<list name="results" table="result" cascade="none" inverse="false">
<key property-ref="registration.info.info_id"/>
<index column="info_id " />
<one-to-many class="Result" />
</list>
I basically want Hibernate to do a join through the chain of objects, and eventually get a SQL that looks like:
SELECT * FROM result,letter,info WHERE letter.info_id=info.info_id AND info.info_id=result.info_id
AND letter.id=?;
Is something like this viable in Hibernate?
Edit:
The tables info and registration have the same id. So info.id=registration.id
. If needed I could add Info into the Letter object.