Hi,
1. If you use Oracle you can use a sequence that you increment with a native SQL query
2. You can probably use your regular EntityManager but load and lock your entity at the same time with a native query such as "SELECT c FROM counter c FOR UPDATE".
3. If you want to minimize locking time, then you can annotate your method getNext() with the REQUIRES_NEW annotation (But then your counter is not in the same transaction than the caller of getNext(), which means it is incremented anyway, a bit like the sequence).
Hope it helps...
[Message sent by forum member 'ewernli' (ewernli)]
http://forums.java.net/jive/thread.jspa?messageID=251323