-->
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.  [ 4 posts ] 
Author Message
 Post subject: Sessions and data integrity
PostPosted: Wed Jun 30, 2004 7:48 pm 
Newbie

Joined: Tue Apr 20, 2004 4:20 am
Posts: 8
Location: Sydney/Australia
Hi all

I just implemented the "Open Session in View pattern" and am a bit concerned about data integrity.

Heres the scenario:

The object:
class Test
{
int Attribute1 = 0;
int Attribute2 = 0;
}

The flow:
1) Request 1 arrives and a new Session is opened for this request. The Action (were using struts) loads an the Test object and goes off and does some calculation

2) Request 2 arrives and a new Session is opened on another Thread for this request. The Action loads the same Test object sets Attribute1 to “2” and Attribute2 to “2” and saves the object.

3) Request 1 finishes the calculation modifies sets Attribute1 to “1” and saves the object.

The Problem/Question:
What’s in the Database?

Is it:
1) Sessions do not know of each other and request 1 and 2 get two completely separate instances of Test. This would mean that the last one who writes the object wins (in this case Request 1). This would result in a Test object in the DB with Attribute1 = “1” and Attribute 2 =”0”
2) Sessions know of each other and they get the same Object back which would result in Attribute1 = “1” and Attribute2 = “2”
3) Hibernate detects that two Sessions modified the same object and throws an exception.
4) ????

Could someone explain to me how it works.

Thanks a lot
Ralph

Code:
Code:
Code:
[quote][/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 30, 2004 7:50 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
3) happens after you turn on optimistic locking, that is automatic versioning. See the Hibernate doco or, highly recommended for questions like this, read Hibernate in Action.

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 30, 2004 7:52 pm 
Newbie

Joined: Tue Apr 20, 2004 4:20 am
Posts: 8
Location: Sydney/Australia
Thanks for your quick reply

What does happen if you do not turn on optimistic locking?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 30, 2004 7:58 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
1)

_________________
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.  [ 4 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.