[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Pessimistic lock

hipa do-not-reply at jboss.com
Wed Jul 9 03:39:39 EDT 2008


I have the table from which I want to get unique values for some entities.

  | 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:

  | ...
  | 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:

  | 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:

  | SELECT ... FROM UNIQUE_GENERATORS WHERE ... FOR UPDATE
  | 
?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4163207#4163207

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4163207



More information about the jboss-user mailing list