-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: LEFT JOIN FETCH problem ?
PostPosted: Tue Jun 29, 2004 9:55 am 
Beginner
Beginner

Joined: Sat Oct 18, 2003 10:19 am
Posts: 21
Location: Belgium
Can anybody have a look at the difference between these queries :

from com.dhl.acg.capacity.model.AccountCapacity accountCapacity
inner join fetch accountCapacity.allocationDay allocationDayAlias
inner join fetch allocationDayAlias.positions positionsAlias
inner join fetch accountCapacity.capacity capacityAlias
inner join fetch accountCapacity.capacityUnits capacityUnitsAlias
inner join fetch capacityUnitsAlias.cargoItems cargoItemsAlias
inner join fetch cargoItemsAlias.bookingSplitPiece bookingSplitPiece
inner join fetch cargoItemsAlias.bookingSplitPosition bookingSplitPosition

where allocationDayAlias.allocation = :allocation and capacityAlias.movementDt >= :fromDate
and (capacityAlias.movementDt <= :untilDate or :untilDate is NULL)

-------------------------
where I have no problem accessing the collection of capacityUnits; but since capacityUnits.cargoItems might be a empty collection, we miss some results. We need a left join there... so I rewrite :
-------------------------

from com.dhl.acg.capacity.model.AccountCapacity accountCapacity
inner join fetch accountCapacity.allocationDay allocationDayAlias
inner join fetch allocationDayAlias.positions positionsAlias
inner join fetch accountCapacity.capacity capacityAlias
inner join fetch accountCapacity.capacityUnits capacityUnitsAlias
left join fetch capacityUnitsAlias.cargoItems cargoItemsAlias
left join fetch cargoItemsAlias.bookingSplitPiece bookingSplitPiece
left join fetch cargoItemsAlias.bookingSplitPosition bookingSplitPosition

where allocationDayAlias.allocation = :allocation and capacityAlias.movementDt >= :fromDate
and (capacityAlias.movementDt <= :untilDate or :untilDate is NULL)

-------------------------
where I have a problem accessing the collection of capacityUnits; the collection of capacityUnits does not seem to be loaded ?! (LazyInit exception)
-------------------------

Other related question is :

In the docs i read : only one collection role may be fetched in a query ? Does this mean I can only have one 'inner/left join fetch object.collectionItems" per query ? I have several cases where this does work ... but not using left joins ....

thx in advance,

Koen

_________________
Koen Maes
Leuven, Belgium


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 29, 2004 9:04 pm 
Regular
Regular

Joined: Wed Dec 17, 2003 1:58 pm
Posts: 102
You can only perform one left join fetch per query.. its one of hibernates current limitations


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 30, 2004 4:05 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Not correct, you can only fetch one collection role, but as many "-to-one" associations as you like.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 30, 2004 4:06 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
It's a good limitation btw, it prevents that you permanently shot yourself in the food.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 30, 2004 4:45 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
hello all,
i think i have opened an issue about this good limitation.
Imagine we have:
A ---- * B
|
|
*
C


If we query like "from A a fetch join a.bs fetch join a.cs"
the parser could detect 2 fetch collections and transform the previous query in two queries like:
from A a fetch join a.bs
and
from A a fetch join a.cs

of course this doen't solve the A---*B---*C case...

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 30, 2004 4:46 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Oh, it should be "foot", not "food" :)

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 30, 2004 11:58 am 
Regular
Regular

Joined: Wed Dec 17, 2003 1:58 pm
Posts: 102
My bad Christian I misunderstood =) I still think we should be able to perform multiple fetch queries... whether or not they get split up into multiple actual SQL queries, it would make life in the Multi Tier'd DAO Webapp world significantly easier... as is I have to write specific methods that are capable of calling Hibernate.Initialize... which is difficult... oh and btw your Manning book rocks =)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 30, 2004 12:03 pm 
Beginner
Beginner

Joined: Sat Oct 18, 2003 10:19 am
Posts: 21
Location: Belgium
Strange to see though that it works fine having multiple INNER JOIN fetch statements (on collections!) but not anymore as soon as LEFT JOIN fetch is involved ???

We really have a performance problem here because the

A -> * B -> * C ends up with several thousands of objects of type C

Our original solution - looping through and calling Hibernate.initialize() - is not an option here because of the numerous round trips to the database....

Even the go-between solution ( fetching type B and looping type C ) is not fast enough here... too many round trips. While it is obvious from our problem domain that a single SQL statement could do the job.



Any idea/hint ?

_________________
Koen Maes
Leuven, Belgium


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.