-->
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.  [ 7 posts ] 
Author Message
 Post subject: Info about proxy attribute of class
PostPosted: Mon May 08, 2006 2:32 pm 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
The Hibernate-3 documentation mentions the following as an attribute of <class>.

Quote:
proxy (optional): Specifies an interface to use for lazy initializing proxies. You may specify the name of
the class itself.


How and when can the interface specified here be used in the application? Any examples available?

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 2:39 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
also check documentation under this section http://www.hibernate.org/hib_docs/v3/re ... ng-proxies


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 2:47 pm 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
Thank you for that link. That helped explain the proxy attribute. I have another question related to Hibernate.initialize() in Section 19.1.4. In a 3-tier application, we usually run into LazyInitializationException because of closed sessions. This section mentions the use of Hibernate.initialize() to initialize collections. What does initialize actually mean on a collection. Does it mean that suppose i invoke Hibernate.initialize(children), then all the related children objects will be loaded from database? Or is it just that the collection is initialized but the children objects are not yet loaded in the collection?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 3:05 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
I guess this will only initialize the proxies/collections and not the actual children. Respective child objects will be loaded as and when the corresponding methods are invoked on child object.

As it says in the API documentation http://www.hibernate.org/hib_docs/v3/ap ... ang.Object)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 3:14 pm 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
I actually had a look at that API documentation, and thats what confused me a bit.

Quote:
it is not guaranteed that the elements INSIDE the collection will be initialized/materialized


It does not mention whether the elements in the collection will be loaded by querying the database. The above statement uses the word 'not guaranteed' which i interpreted as may or may not. Suppose the child elements are not loaded but only is collection is initialized, then when the contents of the collection are used at some later point(when the session is closed) will it throw some exception(LazyInitializationException).

Well, i can surely try out the above things on my own, but currently i dont have the required setup. So if this has a quick answer, i would appreciate.

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 4:27 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
I tried the following code and it worked fine for me with two different sessions.

Code:
session = HibernateUtil.getSessionFactory().openSession();   
Long primKey = new Long( 1 );
HibernatePojo pojo = ( HibernatePojo ) session.get( HibernatePojo.class, primKey );
System.out.println("pojo id   = " + pojo.getId());
System.out.println("pojo name = " + pojo.getName());
         
session.close();
session = null;

session2 = HibernateUtil.getSessionFactory().openSession();
//session2.merge( pojo );               // this commented 3 methods
//session2.refresh( pojo );             // fired an extra query to
//session2.lock( pojo, LockMode.READ ); // load the object from DB

session2.lock( pojo, LockMode.NONE ); // No query to DB to load main object

Set set = pojo.getProperties();
Iterator it = set.iterator();
while ( it.hasNext() ) {
   Property prop = (Property) it.next();
   System.out.println("prop.id   - " + prop.getName() );
   System.out.println("prop.name - " + prop.getValue() );
}



Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 9:55 am 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
Thanks a lot for trying that out.

-Jaikiran


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