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.  [ 5 posts ] 
Author Message
 Post subject: Fetching associations with inner join
PostPosted: Tue Oct 26, 2004 8:26 am 
Beginner
Beginner

Joined: Tue Oct 26, 2004 8:14 am
Posts: 20
Location: Mainz, Germany
Hi all,

I'm wondering why its not possible to fetch an association with an inner join ?

When I define an association with outer-join="true" ( or using FetchMode.EAGER ) hibernate generates: "select from a, b where a.col=b.col(+)"

Defining outer-join="false" produces extra SQL Statements to fetch the association.

Is it not possible to use an inner join ?

Thanks,

Matthias


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 26, 2004 8:29 am 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
you can certainly use inner join using HQL queries

Code:
from eg.Cat as cat
    inner join cat.mate as mate


lookup 11.3. Associations and joins in the hibernate online docs.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 26, 2004 8:47 am 
Beginner
Beginner

Joined: Tue Oct 26, 2004 8:14 am
Posts: 20
Location: Mainz, Germany
My Problem is that when I'm loading an Object with:

MyObject o = (MyObject)session.load(MyObject.class, pk);

I want to retrieve many-to-one associated Objects eagerly. But this works only with outer join="true". I don't understand why its not possible to load these associatens with an inner join without using HQL.

Suggestion:
It is already possible to define a many-to-one association as not null. Hibernate could use this information to fetch the related object using an inner join for performace optimization.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 26, 2004 8:50 am 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
odd, i have an object POF which has 2 many to one mappings. They get loaded by default without using any kind of outer join, and i believe outer-join defaults to false.

can you post your mappings?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 26, 2004 8:59 am 
Beginner
Beginner

Joined: Tue Oct 26, 2004 8:14 am
Posts: 20
Location: Mainz, Germany
Excerpt from Mapping file InvoiceItem.hbm.xml:

...
<many-to-one
name="item"
class="Item"
cascade="none"
outer-join="true"
update="true"
insert="true"
access="property"
column="ITEM_ID"
not-null="true"
/>

<many-to-one
name="stock"
class="Stock"
cascade="none"
outer-join="true"
update="true"
insert="true"
access="property"
column="STOCK_ID"
not-null="true"
/>
...

When outer-join is set to true:
load(IncoiceItem.class,pk); produces 1 SQL Select with outer joins.

When outer-join is set to false:
load(IncoiceItem.class,pk); produces 3 SQL Selects

Thats the behaviour described in "Hibernate in action" Chapter 4 Page 148


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.