users@glassfish.java.net

Re: Locking Issue With Sequences Is There a Better JPA Way?

From: <glassfish_at_javadesktop.org>
Date: Tue, 25 Sep 2007 11:35:59 PDT

I am very surprised that the problem only occurs with TopLink. If an update to the sequence table is required then the row will be not be writable by other transactions.

In JPA there are no 'two-phased' commits so each transaction that you are using is independent. Persisting all of the children first in a single transaction then persisting the parents would provide the same functionality without the transactional conflicts.

You could use a seperate EntityManger for acquiring sequences by calling persist on the second EntityManager which will assign the sequences, then clearing that EntityManager but still commit it to ensure the transaction commits the changes to the Sequence Table. Not a 'pretty' solution but workable.

You could also attempt to put all of the work in a single transaction using EM.flush() followed by EM.clear(). (There is currently a bug (being resolved right now) in TopLink Essentials that still limits the size of the transaction) This combination of calls will extend the size of the transaction.

-Gordon
[Message sent by forum member 'gyorke' (gyorke)]

http://forums.java.net/jive/thread.jspa?messageID=237004