-->
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.  [ 13 posts ] 
Author Message
 Post subject: outer-join setting and proxy class
PostPosted: Mon Mar 22, 2004 10:58 am 
Regular
Regular

Joined: Fri Nov 07, 2003 6:31 am
Posts: 104
Location: Beijing, China
Hi everyone,

sorry for the stupid question, but i need to be sure:

Does it makes any sense to insert a outer-join="true" if the associated class HAS a proxy??

Or is Hibernate going to eager fetch this proxied class and instanciate it each time? and even in this case, it might be usefull for the class to be lazy instanciated for any other use of it.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 12:14 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
If you have A many-to-one-with-outer-join-true B (proxy), Hibernate will load both instances of A and B if you load A, with a single outer join select. The proxy setting is not relevant.

If you have A many-to-one-with-outer-join-false (proxy), Hibernate will only load A and use a proxy for B. A second select will be used to fetch B on demand.

If you have A many-to-one-with-outer-join-true (no proxy), Hibernate will load both instance of A and B if you load A, with a single outer join select.

If you have A many-to-one-with-outer-join-false (noproxy), Hibernate will use two selects to fetch A and B when A is loaded.

Please note that for one-to-one and many-to-one associations, outer-join fetching is usually enabled by default (auto). You can control this behavior with the max_fetch_depth Hibernate property (0 turns it off).

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 12:44 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Christian,
i've seen this kind of question many times.
Quote:
If you have A many-to-one-with-outer-join-false (proxy), Hibernate will only load A and use a proxy for B. A second select will be used to fetch B on demand.

It is easy to code such a proxy?

Thanks,
Anthony


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 12:46 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Set <class lazy="true"> and have a no-arg constructor with package visibility. Thats all.

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 12:58 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
that's all?
great, thanks a lot!
Last question, what will happen if <class lazy="false"> ..., i mean is it supported for the previous versions (especially 2.0)



Anthony


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 1:07 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Please read the documentation, "Performance" chapter. Setting lazy=false disables proxying for this class.

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 1:15 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
oh, excuse me, in fact the question was: for previous versions, the lazy attribute is not available (for a class) so for previous versions it will work as if lazy="true" ?
But no problem, i will download previous docs tomorrow and test it.

Anyway, thank you.

Anthony


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 1:20 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
lazy="true" is in that case just a shortcut for proxy="theNameOftheProxyClassIsTheSameAsTheBaseClass"

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 2:34 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
ok, thanks again Christian


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 10:48 pm 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:02 am
Posts: 46
Location: Kuala Lumpur, Malaysia
Christian,

[quote]Set <class lazy="true"> and have a no-arg constructor with package visibility. Thats all.[/quote

I had a read of the chapter on performance but it doesn't really say what's needed in the proxy class specified in the proxy attribute. <class name="foo" proxy="myProxy"> What i've done is just extract an interface from my persistent class (Eclipse makes this easy) and plonk that in. I hope I'm doing the right thing.

Regards,

Alistair


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 11:16 pm 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:02 am
Posts: 46
Location: Kuala Lumpur, Malaysia
OK. After testing this, it works fine to just name your persistent class itself in the proxy attribute. CGLIB performs magic behind the scenes. It's working.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 3:49 am 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:02 am
Posts: 46
Location: Kuala Lumpur, Malaysia
However, ... I have one more question.

Code:
   /**
    * @hibernate.many-to-one
    *      column = "orig_id"
    *      class = "Foo"
    *      unique = "true"
    *      cascade = "none"
    */
   public FooProxy getFoo() {
      return foo;
   }

My property is now set to be of type FooProxy, an interface. Should I change my relationship in the mapping file to point to the original class, Foo or the FooProxy ?

Regards,

Alistair


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 5:49 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You should not do anything special :) Set lazy="true" for your class and have a package visible no-arg constructor. Hibernate will do the rest.

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


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