-->
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.  [ 9 posts ] 
Author Message
 Post subject: Is lazy="extra" possible with EJB3?
PostPosted: Tue Jan 03, 2006 4:48 pm 
Beginner
Beginner

Joined: Wed Jun 15, 2005 1:28 pm
Posts: 39
Location: United States
I would like to use the functionality of lazy="extra" with my EJB3 entity. Is this possible? The FetchType class only contains two choices: LAZY and EAGER.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 6:02 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No but this is a simple task to add, patch welcome.
We need to introduce a @Fetch annotation

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 2:15 am 
Beginner
Beginner

Joined: Wed Jun 15, 2005 1:28 pm
Posts: 39
Location: United States
Sure, I will contribute this as a patch.


Top
 Profile  
 
 Post subject: design of extraLazy
PostPosted: Wed Jan 11, 2006 1:21 pm 
Beginner
Beginner

Joined: Wed Jun 15, 2005 1:28 pm
Posts: 39
Location: United States
I completed the addition of the @Fetch annotation and began to test our application. I have a patch to CVS source ready.

What I have discovered is that even with extraLazy turned on for a collection, Hibernate still does further database access when size() is called on an uninitialized Set. I would like to discuss this design and see if I could make further changes which would enhance the framework.

What we are trying to achieve with extraLazy in our application is the avoidance of further database activity (after session is closed) when an uninitialized collection is returned to the middle tier.

The middle tier (java) is a third party product dedicated to data serialization and deserialization of data between client and server.
A call to size() is needed for this serialization layer to know how many records exist, to build an array.

We want the real size of the Set to be returned. For an uninitialized Set, size() should return 0. If the Set has been initialized because of a 'fetch all' or because of a lazy init, then the size should be the number of entries in the Set.

As this time, the call to size() is throwing LazyInitializationException because we're not connected. The data has been assembled in the DAO, and should be used as-is. Hibernate assumes we always want the size() in the database, and thus an uninitialized collection can never have an uninitialized size.

I propose I make further changes to simply return actual rows in the Set for extraLazy collections. If the database record count is needed, there could be a call specific to this requirement.

Emmanuel, please give me your feedback when you have a chance. Thanks.


Top
 Profile  
 
 Post subject: extraLazy iterator
PostPosted: Wed Jan 11, 2006 8:12 pm 
Beginner
Beginner

Joined: Wed Jun 15, 2005 1:28 pm
Posts: 39
Location: United States
I would also like to propose adding extra lazy functionality to some of the other functions of a collection. This would allow more modular applications to be written with Hibernate as their persistance framework.

For example, if an application tries to use an iterator to loop through an uninitialized collection, initialization is forced even before the iterator object is created. What is desirable in our case is that we want to iterate through an empty collection. The first iterator.hasNext() call would return false and no processing would take place. We intend that the collection remain uninitialized until the client makes further function calls to ask for the data.

In our case this application is in the middle tier of the architecture, dedicated to data serialization. Because it's a java system, Hibernate is still watching the objects, but by the time they are passed in the session is closed.

One might be asking at this point just when exactly would a lazy init be desriable in our extra lazy configuration? The answer to that question is "only when we specifically ask for it".

I could see a loadAll() function being handy for finding all uninitialized extra lazy collections in an entity and loading them, with an option to go "deep". I could also see a load() function on a collection to init just one collection.

I see that the session is still required in order for Hibernate to check if a collection is lazy or not. Since our serialization framework takes over after the session is closed, we would need to remember that extraLazy is true for a collection (in AbstractPersistentCollection) after the session is closed. I believe then the call to throwLazyInitializationExceptionIfNotConnected() would be unneeded when it just preceeds if (persister.isExtraLazy()).

We are willing to make these contributions if they would be included in the framework.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 12, 2006 3:58 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
lazy=extra does not mean returning wrong values, it means minimizing the amount of data retrieved from the DB at the cost of more roundtrips.
Based on this assumption:

-1 on size()
-1 on iterator.hashNext()

All of them are calls to ask for real data, not fake ones.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Fetch annotation
PostPosted: Fri Jan 13, 2006 4:43 pm 
Beginner
Beginner

Joined: Wed Jun 15, 2005 1:28 pm
Posts: 39
Location: United States
Emmanuel, do you have a JIRA case which I can submit the @Fetch patch to?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 15, 2006 3:01 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
nope, open a new one

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 15, 2006 5:50 pm 
Beginner
Beginner

Joined: Wed Jun 15, 2005 1:28 pm
Posts: 39
Location: United States
http://opensource2.atlassian.com/projects/hibernate/browse/ANN-224


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