views:

35

answers:

1

I have two tables

tab1 { col1 (PK), col2, col3 }

tab2 { col1, col2(PK), col3 }

I am using Hibernate annotation for joining using "OneToOne"

I have the below Hibernate class for tab1

class tab1 {
   @OneToOne
   @JoinColumn(name = "col2", referencedColumnName = "col1")
   private tab2 t2;
}

i was expecting to run the below sql

select * from tab1 t1, tab2 t2 where t1.col1 = t2.col2

But it is not working as i expected.Please help

A: 

If you want to retrieve tab1 entities and to eager load the associated tab2 using a single select, use a "fetch" join:

SELECT t1 from Tab1 t1 left join fetch t1.t2

You need to think associations and to navigate through associations when working with an ORM.

Pascal Thivent