-->
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: immediate lock after read (Select for update)
PostPosted: Wed Oct 20, 2010 6:38 am 
Newbie

Joined: Wed Oct 20, 2010 6:17 am
Posts: 4
Hello,

i want to read a object out of the database and lock it while/ immediate after reading.
I only found this way:
Code:
session.lock(object, lockMode)

and of course HQL.
Unfortunately, both are NOT compatible with my application design, cause i read with the aid of logics.

Now i'm looking for a solution like the following :
Code:
ArticleLogic al = new ArticleLogic();
al.setFilter(ArticleLogic.FILTER_SERIAL_NUMBER, "123456");
al.setFilter(ArticleLogic.FILTER_LOCK, true);

Article tempArticle = al.unique();

tempArticle.setStatus("reserved");

session.update(tempArticle);


It should produce a SQL statement like this:

SELECT * FROM article WITH (UPDLOCK) WHERE serial_number = '123456'

The selected record should immediate gets locked.

I hope someone recognize my need and help me out.

Thanks and regards,

MK


Top
 Profile  
 
 Post subject: Re: immediate lock after read (Select for update)
PostPosted: Wed Oct 20, 2010 7:03 am 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
Try to use LockMode.UPGRADE


Top
 Profile  
 
 Post subject: Re: immediate lock after read (Select for update)
PostPosted: Thu Oct 21, 2010 3:23 am 
Newbie

Joined: Wed Oct 20, 2010 6:17 am
Posts: 4
Hello,

i found a way with the aid of the Criteria API.
Code:
if (this.isFilter(ArticleLogic.FILTER_LOCK_READ))
{
   articleCriteria.setLockMode(LockMode.PESSIMISTIC_WRITE);
}


Regards,

MK


Top
 Profile  
 
 Post subject: Re: immediate lock after read (Select for update)
PostPosted: Wed Dec 14, 2011 8:52 pm 
Newbie

Joined: Fri Dec 09, 2011 12:35 am
Posts: 2
It is obvious that I really want to be part of your site. I really love how you make people to have an interest in your site which helps me a lot. Thank you so much for this.

_________________
door lock
electric strikes


Top
 Profile  
 
 Post subject: Re: immediate lock after read (Select for update)
PostPosted: Sat Dec 17, 2011 6:55 am 
Newbie

Joined: Sat Dec 17, 2011 6:23 am
Posts: 1
Thanks for providing me the answer of the question I was just looking for.
----------------------------------------------------------------------------------------------
Kosher Wine


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.