-->
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.  [ 5 posts ] 
Author Message
 Post subject: getting objects outside a session
PostPosted: Thu May 08, 2008 2:53 am 
Regular
Regular

Joined: Thu Sep 16, 2004 4:56 pm
Posts: 80
Someone challenged me about how hibernate's LazyInitializationException is stupid. After thinking about it quite some time, I started to think that maybe he is right. Why not allow shirt.getDesigner() to load the Designer object from the database outside the session? It is just a read query. I was so sucked into the application transaction pattern, that I don't have a good concrete example of why doing it his way would be bad(his way is simply allowing shirt.getDesigner to work......every other hibernate feature stays the same except this allow loading outside of a transaction).
I mean, the object does not necessarily need to be related to it's specific session, does it? In fact, I think it causes alot of confusion. Can someone come up with an example where turning on this feature would be a bad thing? I keep thinking there may be one but I can't think of it. Maybe my colleague is correct in that this part of hibernate is a flaw(but it's hard to believe as hibernate has been in production for soooo long).

thanks,
Dean

_________________
The list of compelling reasons to reduce the estimate does not include you simply wishing it would take less time - Unknown


Top
 Profile  
 
 Post subject: almost forgot to add this....
PostPosted: Thu May 08, 2008 4:33 am 
Regular
Regular

Joined: Thu Sep 16, 2004 4:56 pm
Posts: 80
I know hibernate is trying make sure you don't have non-repeatable reads, but how often is one really going to read the same thing twice in a transaction? I mean, maybe there should be an option to turn off LazyInitException so those who don't need repeatable reads have an easier time developing the application?

Is there LARGE performance differences if opening a tx for every read maybe as that is what would happen outside the session?

_________________
The list of compelling reasons to reduce the estimate does not include you simply wishing it would take less time - Unknown


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 08, 2008 2:48 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Have a look at Gavin's reply on this thread:

http://www.jboss.com/index.html?module= ... c&start=10

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 08, 2008 2:53 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
And it's all summed up here:

http://www.hibernate.org/43.html

See: "Why can't Hibernate just load objects on demand?"

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 08, 2008 6:46 pm 
Regular
Regular

Joined: Thu Sep 16, 2004 4:56 pm
Posts: 80
I had already been there and read that. I still need a concrete example to show this guy. I can't continue the argument without proof and when I can't prove something, I start to tend to think that maybe the other guy is right.

I posted my own(albeit unlikely to happen) example at the bottom of that web page you gave me yesterday before you responded to my post. My main question is I would love an example where this is a problem.....

" What happens when Hibernate opens a new database connection to load a collection, but the owning entity has been deleted meanwhile?"

in hibernate, I am curious now what happens in this case and am going to write a test today. maybe I will be able to find my own example.

1. I get a shirt
2. shirt is deleted in another transaction
3. shirt.getBuyers() with hibernate would return what...all the shirts I suppose where if you had random transaction behavior...you would get what? hmmm. what would be the response to that...exception....that seems kind of nasty. I think I understand this a bit better now maybe.

As far as this comment there.....

"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?"

You run into this problem regardless with detached entities tree getting bigger and bigger so I totally disagree with the memory comment. objects are evicted by garbage collection as I stop using them and I am smart enough to be sticking ones I want in a session and ones I don't not in a session and those not in the session are cleaned up. Others are removed from my web session later when I don't need them anymore.

_________________
The list of compelling reasons to reduce the estimate does not include you simply wishing it would take less time - Unknown


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