Hi
I'm confused with setFetchMode.
I have a 3 tables:
BSCSContractAll n <---> 1 BSCSCustomerAll n <---> 1 BSCSBillcycles
When I write a query:
Code:
final BSCSContractAll bscsContractAll =
(BSCSContractAll)
PersistenceUtil.getHibernateSession(em)
.createCriteria(BSCSContractAll.class)
.setFetchMode("bscsCustomerAll", FetchMode.JOIN)
.setFetchMode("bscsCustomerAll.bscsBillcycles", FetchMode.JOIN)
.add(Restrictions.idEq(iCoId))
.uniqueResult();
... everything works perfectly, I mean there is the only one SQL against all 3 tables joined (by Hibernate) respectively.
But when I use only one single association path "bscsCustomerAll.bscsBillcycles":
Code:
final BSCSContractAll bscsContractAll =
(BSCSContractAll)
PersistenceUtil.getHibernateSession(em)
.createCriteria(BSCSContractAll.class)
.setFetchMode("bscsCustomerAll.bscsBillcycles", FetchMode.JOIN)
.add(Restrictions.idEq(iCoId))
.uniqueResult();
... then Hibernate generates a SQL query only against one (first) table: BSCSContractAll :(
So my question is:
Is specifying only one association path "bscsCustomerAll.bscsBillcycles" not enough to instruct Hibernate that I want to join *all 3* in a one single SQL?
btw:
Looking on Java file in hibernate-3.3.1 distribution I found both approaches - two pieces of Hibernate test code:
Single association path:
Code:
list = s.createCriteria(Foo.class)
.setFetchMode("component.importantDates", FetchMode.EAGER)
.list();
Both association paths:
Code:
parents = s.createCriteria(Parent.class)
.setFetchMode("moreChildren", FetchMode.JOIN)
.setFetchMode("moreChildren.friends", FetchMode.JOIN)
.addOrder( Order.desc("name") )
.list();
I'm confused...
Take care and have a nice weekend!
Adam Wozniak