Hello All,
I am currently evaluating Hibernate 3.2.
I am working with a query which uses FETCH JOINS across 3 tables and returns a list of entities. I expected a single select but in fact am getting multiple selects. I would like to know if anybody has experienced similar behavior and if hibernate is working as designed. I have not come across any documentation explaining this behavior so thought I would come to the experts.
My test case was using 3 entities, with bi-directional required one-to-one relationships between the tables :
SC (1 <--> 1) AC (1 <--> 1) AP
where AC has a foreign key to SC and a foreign key to AP.
I had the following named query which retrieved AC objects and did a FETCH JOIN to load the SC and AP objects :
Code:
@NamedQuery(name="AC.findACListByValue",
query="SELECT DISTINCT c FROM AC c JOIN FETCH c.ap JOIN FETCH c.sc " + "WHERE c.value = :value")
If I ran this query with 5 rows in each table, hibernate would execute 11 selects :
1. The original named query
2. 5 selects on AC where criteria was foreign key SC
3. 5 selects on AC where criteria was foreign key AP
I was expecting a single query. When I changed the relationship to uni-directional, a single query was executed and it loaded all 15 entities.
Is this expected behavior?
Any help or suggestion would be much appreciated.
Regards,
Kurt