-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to use Proxy?
PostPosted: Tue Sep 14, 2004 1:14 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
Hi everyone:

I see the hibernate docs http://www.hibernate.org/hib_docs/reference/en/html/performance.html .
The proxy puzzled me some time. Need I have to use proxy if I want to lazy load? If not , what time should I use proxy? I also don't understand how to use interface to implements proxy. Could someone give me a example or tell me how to use proxy to improving performance?

THks in advance!

_________________
You are not alone...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 14, 2004 6:48 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
The best answer to your question is "try it yourself and look at the generated SQL"...


In short, you can have lazy collections and lazy entities.

A lazy collection is a collection that will be fetched from the database the first time you access it. This means the collection won't be populated at the time you retrieve the owning entity.


A lazy entity is an entity whose properties will be loaded from the database the first time you access it. It makes sense (and is usefull) only when the entity is a member of a collection or the target of a many-to-one relationship. In this case, Hibernate won't load the entity but initialize a proxy for it (at this stage, Hibernate knows the entity exists and the correponsing primary key - that's all the proxy contains besides the entity class).

Example: a Child as a one and only one Parent. Suppose the Parent entity is declared lazy. When you load a child, the parent entity will be loaded only at the time you call child.getParent() (returning a populated instance of the Parent class).

It is enough to add 'lazy=true' in the Parent class mapping to make it lazy. Don't botter now with the interface stuff...


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