cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From YK 7 <>
Subject Re: Cayenne external transaction
Date Mon, 20 Feb 2012 20:42:49 GMT
Thanks for this brilliant answer Andrus!

However, I still have a question.
Suppose that we have two databases and that we commit to the second one
only if the commit to the first db succeeds.
If I well understood, here I have to use external tx because it offers more

Is it better to have an ObjectContext per DataNode (and not per DataDomain)
so that we can handle all cases?


On Sun, Feb 19, 2012 at 1:51 PM, Andrus Adamchik <>wrote:

> 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

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message