-->
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.  [ 1 post ] 
Author Message
 Post subject: Pessimistic lock
PostPosted: Fri Jul 11, 2008 7:05 am 
Newbie

Joined: Wed Jun 06, 2007 2:03 am
Posts: 2
I have the table from which I want to get unique values for some entities.


Code:
public class UniqueGenerator
{
    @Id
    @Column(...)
    private String id;

    @Column(...)
    private Long currentValue;
    ...
}



Then in data access layer I have to write this code to retrieve next value:

Code:
...
gen = entityManager.find(UniqueGenerator.class, MY_GENERATOR_ID);
entityManager.lock(gen, LockModeType.WRITE);
entityManager.refresh(gen);

Long currVal = gen.getCurrentValue();
...



Hibernate translate it to these 3 queries:

Code:
1. SELECT .. FROM UNIQUE_GENERATORS WHERE ...
2. SELECT GENERATOR_ID FROM UNIQUE_GENERATORS WHERE ...FOR UPDATE
3. SELECT .. FROM UNIQUE_GENERATORS WHERE ...


Is there any way to make Hibernate doing only one query:
Code:

Code:
SELECT ... FROM UNIQUE_GENERATORS WHERE ... FOR UPDATE


?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.