I'm new to Cayenne and I'm testing the Cayenne's transaction management
using the following scenario:
I have a simple web application that uses Spring to create
singletons(Services, DAOs...) and make the dependencies injection.
My example is using two different Databases (MySQL and Oracle) and thus, I
have defined two Cayenne Server Runtimes:
One for Oracle and one for MySQL. Those two ServerRuntimes are instantiated
once in a singleton.
The ObjectContexts are instantiated once per HTTP session and sent to the
DAOs via ThreadLocal (This is very similar to the Cayenne's HTTP filter).
Everything works well if I use directly objectContext.commitChanges()
method to commit changes to DB.
What I'm trying to do next is to use Cayenne Transactions using :
Transaction tx = serverRuntime.getDataDomain().createTransaction().
tx.commit(); //or tx.rollback() depending on the situation
The problem here is that if I do so, it means that if a user(or HTTP
session) changes are committed, all other users(or HTTP sessions) changes
will also be committed.
This is because serverRuntime is a singleton and the transaction is created
against it (and not against the objectContext which is bound to the HTTP
I also took a look at the ServerRuntime source code and noticed that it
defines two instance properties (injector and modules which are in the
parent class: CayenneRuntime).
If I'm not mistaken, this means that ServerRuntime is not a good candidate
to be defined as a singleton (one instance per application).
Maybe I'm not correctly using Cayenne to manage transaction when we have
more than one server runtime. If so, what's the best way to achieve that