-->
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.  [ 6 posts ] 
Author Message
 Post subject: Optimistic locking w/ lazy loading in a client app
PostPosted: Wed Jun 02, 2004 12:38 pm 
Newbie

Joined: Wed Jun 02, 2004 11:58 am
Posts: 3
I have a client application (Swing) that uses Hibernate 2.1 for database access (SQL Server).

I'm using optimistic locking (w/ version numbers). I'm also using lazy loading to get rid of some performance bottlenecks when retrieving large resultsets.

Since my application always runs in a single thread, I keep the Hibernate Session, and only one Session, open throughout the application lifecycle. It is opened when the application starts, and closed when the application terminates. I am not closing the Session after transactions, etc.

The application maintains a single instance of each persistent object (more or less, some reports in the application do things a little differently).

I'm having a few problems with combining lazy loading and recovering from StaleObjectStateExceptions.

Two problems:

1) if I open the session before each transaction and close it after the transaction has completed, lazy loading stops working.

2) if I don't open and close the session before and after each transaction, I can not recover from StaleObjectStateObjections. I'm doing session.refresh(myBean) after the exception, but that does not update the optimistic locking version number of the entity the SessionImpl class keeps cached.

I've read about the ThreadLocal approach, long transactions (disconnect() and reconnect()), but these are not working either. The information I have been able to find to help me with this, is all geared towards web based development and I'm having a hard time figuring out how it all applies to my problem.

Anyone out there able to help me with this?

Thanks!

-TPP


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 02, 2004 12:41 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Quote:
Since my application always runs in a single thread, I keep the Hibernate Session, and only one Session, open throughout the application lifecycle. It is opened when the application starts, and closed when the application terminates. I am not closing the Session after transactions, etc.


So, basically you are working with stale data all the time. Learn how update() and lock() works.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 02, 2004 12:45 pm 
Newbie

Joined: Wed Jun 02, 2004 11:58 am
Posts: 3
christian wrote:
Quote:
Since my application always runs in a single thread, I keep the Hibernate Session, and only one Session, open throughout the application lifecycle. It is opened when the application starts, and closed when the application terminates. I am not closing the Session after transactions, etc.


So, basically you are working with stale data all the time. Learn how update() and lock() works.


Care to elaborate?

-TPP


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 02, 2004 12:50 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://www.hibernate.org/hib_docs/refer ... c-detached

http://www.hibernate.org/Documentation/ ... ctionScope

Getting Hibernate in Action is also not a bad idea, as always ;)

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 02, 2004 1:31 pm 
Newbie

Joined: Wed Jun 02, 2004 11:58 am
Posts: 3
christian wrote:
http://www.hibernate.org/hib_docs/reference/en/html/transactions.html#transactions-optimistic-detached

http://www.hibernate.org/Documentation/ ... ctionScope


I've read all that and tried the different approaches already.

I still can not get recovery from stale data exception and lazy loading to work at the same time.

If I open/close sessions, lazy loading does not work, but I can recover from stale data exceptions. This is the piece I can't figure out.

Do I have to reload the "root" object before accessing the collections I'm trying to lazy load? These collections are accessed in separate application transactions (to use the term from the latter document) from loading the "root" objects.

-TPP


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 02, 2004 1:44 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
An object has to be associated with a connected Session if you want to load lazy properties.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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