cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <>
Subject Re: Transaction Isolation level SERIALIZABLE
Date Thu, 04 Oct 2007 08:37:29 GMT

On Oct 4, 2007, at 10:46 AM, Martin Thelian wrote:

> Hi!
> What transaction isolation level is used by cayenne

By default in-memory changes to the DataContext are not wrapped in a  
transaction. Life-span of an underlying DB transaction is much  
shorter, roughly corresponding to the 'performQuery' or  
'commitChanges' method call.

> and is there a way
> to change it to use serializable transactions?

There's no direct API (maybe we should add it to Cayenne Transaction  
in 3.0?), but you can enable serializable transactions by wrapping  
your code in a Cayenne transaction manually [1] (see "User-Defined  
Transaction Scope" down the bottom), and setting Connection  
properties by hand. Modifying the example from the docs:

DataDomain domain = Configuration.getSharedConfiguration().getDomain();
Transaction tx = domain.createTransaction();
try {

    DataNode node = domain.getNode("MyNode");

    // this returns shared thread connection
    Connection c = node.getDataSource().getConnection();


> If this is not possible, what other possibilities do I have to lock
> table rows or to at least detect concurrent changes? The only hint  
> I've
> found is a description how to use optimistic locking in [1].

Yes, optimistic locking is a good strategy for concurrency management  
(wonder why this page is not a part of the User Guide?).



View raw message