-->
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: @OneToOne and 1:n selects
PostPosted: Thu Mar 15, 2007 4:41 pm 
Newbie

Joined: Thu Mar 15, 2007 3:58 pm
Posts: 2
Hi all,

we are using Hibernate 3.2.0 and Spring. No hbm.xml files, just annotations.
I wonder whether there is a way to configure Hibernate to fetch @OneToOne unidirectional relations in one select when fetching owning entity.
Entities are joined by FK.
For example
Code:
SELECT a FROM SomeObject a

always produces a bunch of selects to retrieve 1-1 associations.

To get entity in a single select you have to explicitly specify left join fetch in JPQL query, none of config options or Hibernate annotations worked, for example
Code:
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name="some_fk")
@LazyToOne(value = LazyToOneOption.FALSE)
@Fetch(value = FetchMode.JOIN)

has no effect

Am I missing something here or is it the explicit query the only option ?

Thank you for any info


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 6:15 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
the explicit query is the expected option. It qllow fine grained choice.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 6:11 am 
Newbie

Joined: Thu Mar 15, 2007 3:58 pm
Posts: 2
emmanuel wrote:
the explicit query is the expected option. It qllow fine grained choice.


According to JPA spec 1-1 associations are by default loaded eagerly. It is interesting why they then can't be loaded by default in a single query, or at least to have that configurable at association/class level. Now for big result sets this is certainly disadvantage in terms of performance and one has to explicitly specify fetch joins on associations to reduce roundtrips to datastore.
Any comments ?


Top
 Profile  
 
 Post subject: Different behavior 3.2.0/3.3.0
PostPosted: Fri Mar 23, 2007 6:40 pm 
Newbie

Joined: Thu Nov 30, 2006 3:08 pm
Posts: 5
I'm getting different behavior w/ Hibernate/Annotations 3.2.1/3.2.0 and 3.2.2/3.3.0.

FetchType.EAGER works with 3.2.1/3.2.0, but not with 3.2.2/3.3.0.

3.2.1/3.2.0 SQL:

Hibernate: select sidetasks0_.shipmentInfo_sideTasks_id as shipment4_3_, sidetasks0_.id as id3_, sidetasks0_.id as id1_2_, sidetasks0_.type as type1_2_, sidetasks0_.details as details1_2_, sidetasks0_.shipmentInfo_sideTasks_id as shipment4_1_2_, shipmentin1_.id as id0_0_, shipmentin1_.shipmentId as shipmentId0_0_, shipmentin1_.file as file0_0_, shipmentin1_.newShipmentForm_id as newShipm6_0_0_, shipmentin1_.currentTask_id as currentT5_0_0_, shipmentin1_.whitewaterJobId as whitewat4_0_0_, newshipmen2_.id as id3_1_, newshipmen2_.sendingUserImId as sendingU2_3_1_, newshipmen2_.sendingStationImId as sendingS3_3_1_, newshipmen2_.receivingUserImId as receivin4_3_1_, newshipmen2_.receivingStationImId as receivin5_3_1_, newshipmen2_.filename as filename3_1_ from ShipmentTask sidetasks0_ left outer join ShipmentInfo shipmentin1_ on sidetasks0_.id=shipmentin1_.currentTask_id left outer join NewShipmentFormEntity newshipmen2_ on shipmentin1_.newShipmentForm_id=newshipmen2_.id where sidetasks0_.shipmentInfo_sideTasks_id=?

3.2.2/3.3.0 SQL:

Hibernate: select shipmentin_.id, shipmentin_.currentTask_id as currentT6_0_, shipmentin_.newShipmentForm_id as newShipm
5_0_, shipmentin_.whitewaterJobId as whitewat4_0_ from ShipmentInfo shipmentin_ where shipmentin_.id=?

Hibernate: select newshipmen_.id, newshipmen_.filename as filename3_, newshipmen_.receivingStationImId as receivin3_3_,
newshipmen_.receivingUserImId as receivin4_3_, newshipmen_.sendingStationImId as sendingS5_3_, newshipmen_.sendingUserIm
Id as sendingU6_3_ from NewShipmentFormEntity newshipmen_ where newshipmen_.id=?

Query is simply: session.createCriteria(ShipmentInfo.class).list()

Did something change in 3.3.0?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 8:30 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you do not give enough information to say

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 8:34 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
plus the first one involve shipment task, the others not. It's suspicious :-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 9:03 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
using Annotations and Core, I can't reproduce, so wo a running test case...

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 11:58 am 
Newbie

Joined: Thu Nov 30, 2006 3:08 pm
Posts: 5
Sorry, I got the selects confused with those of some other operation.


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.