0

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.

Aniket Kulkarni
  • 12,825
  • 9
  • 67
  • 90
Andres Olarte
  • 4,380
  • 3
  • 24
  • 45

1 Answers1

0

As per the link here . Relationship can be maintained only using the inner joins. So, Yes, you can do it. you may have to add the registration.id = info.id manually into the query.

Community
  • 1
  • 1
Zeus
  • 6,386
  • 6
  • 54
  • 89