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.
|