cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ashley Aitken <>
Subject Re: lazy loading (slightly OT but still pretty important)
Date Thu, 29 Mar 2012 15:24:23 GMT

Just jumping in here but this may also be interesting to consider given the discussion so

> Why can't Hibernate just load objects on demand?
> Every month someone has the idea that Hibernate could instead of throwing a LazyInitializationException
just open up a new connection to the database (effectively starting a new Session) and load
the collection or initialize the proxy that has been touched on-demand. Of course, this idea,
while brilliant at first, has several shortcomings that only appear if you start to think
about the consequences of ad-hoc transactional access.
> If Hibernate would, hidden from the developer and outside of any transaction demarcation,
start random database connections and transactions, why have transaction demarcation at all?
What happens when Hibernate opens a new database connection to load a collection, but the
owning entity has been deleted meanwhile? (Note that this problem does not appear with the
two-transaction strategy as described above - the single Session provides repeatable reads
for entities.) Why even have a service layer when every object can be retrieved by simply
navigating to it? How much memory should be consumed by this and which objects should be evicted
first? All of this leads to no solution, because Hibernate is a service for online transaction
processing (and certain kinds of batch operations) and not a "streaming objects from some
persistent data store in undefined units of work"-service. Also, in addition to the n+1 selects
problem, do we really need an n+1 transaction and connection problem?
> The solution for this issue is of course proper unit of work demarcation and design,
supported by possibly an interception technique as shown in the pattern here, and/or the correct
fetch technique so that all required information for a particular unit of work can be retrieved
with minimum impact, best performance, and scalability



Ashley Aitken
Perth, Western Australia (GMT + 8hrs!)
Social (Facebook, Twitter, Skype etc.): MrHatken 
Professional (LinkedIn, Twitter, Skype etc.): AshleyAitken

View raw message