cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: Cayenne external transaction
Date Sun, 19 Feb 2012 12:51:39 GMT
External transactions allow you to use container-managed DataSource and tie Cayenne in to container-managed
JDBC transactions. So essentially if a container does a commit or rollback on a Connection,
this will commit/rollback everything that was flushed via Cayenne or other JDBC clients since
the start of the transaction.

DataNode by itself is stateless. It is just a driver on top of JDBC driver if you may. So
no problems there. 

ObjectContext state is not tied directly to the transaction. Its commit within an external
tx is a flush to DB that will be committed or rolled back at some later point at tx end. You
can do multiple ObjectContext commits within the same tx to update data incrementally, etc.
ObjectContext rollback is even less related to tx. It just reverts objects in memory back
to their previously known committed state. In many cases you probably do not want to reuse
the context between external transactions.

And finally, consider whether you really need those external transactions. 90% of Cayenne
apps don't. A common reason to use external tx is when you want atomic behavior across multiple
sources of DB modification (say Cayenne and raw JDBC) or mixing Cayenne with other non-JDBC
transactional resources (JMS for instance). If you only modify the DB via Cayenne, then you
don't need external tx. This is what makes Cayenne unique in the ORM space, and so much easier
to use. It was compared to a version control system by other users - you check out a local
copy of your objects, you modify them, and then commit. Only the last step involves a transaction
and Cayenne can handle starting and ending it internally with no user involvement.

Cheers,
Andrus



On Feb 18, 2012, at 5:48 PM, YK 7 wrote:
> In Cayenne Modeler, when I disable Cayenne managed transactions, a message
> saying that the external transaction was used instead during a commit.
> 
> How am I supposed to tell my external container to handle transaction if
> cayenne manages DB objects(Node, ObjectContext...) ?
> 
> Do you have any working example that shows how to use cayenne with the same
> circumstances?
> 
> thx


Mime
View raw message