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
?