<p>We have an existing C++ application that we are going to gradually replace with a new Java-based system.  Until we have completely reimplemented everything in Java we expect the C++ and Java to have to communicate with each other (RMI, SOAP, messaging, etc - we haven't decided).</p>

<p>Now my manager thinks we'll need the Java and C++ sides to participate in the same Oracle DB transaction.  This is related to, but different from the usual distrbuted transaction problem of having a single process co-ordinate 2 transactional resources, such as a DB and a message queue.</p>

<p>I think propagating a transaction across processes is a terrible idea from a performance and stability point-of-view, but I am still going to be asked for a solution.</p>

<p>I am familiar with XA transactions and I've done some work with the JBoss Transaction Manager, but my googling hasn't turned up anything good on propagating an XA transaction between 2 processes.</p>

<p>We are using Spring on the Java side and their documentation explicitly states they do not provide any help with transaction propagation.</p>

<p>We are not planning on using a traditional Java EE server (for example: IBM Websphere), which may have support for propagation (not that I can find any definitive documentation).</p>

<p>Any help or pointers on solutions is greatly appreciated.</p>

[{'answer_id': 87500, 'author': 'Justin Cave', 'author_id': 10397, 'author_profile': 'https://Stackoverflow.com/users/10397', 'pm_score': 3, 'selected': False, 'text': '<p>There is <a href="http://laurentschneider.com/wordpress/2008/08/read-uncommitted.html" rel="noreferrer">an example on Laurent Schneider\'s blog</a> of using the DBMS_XA package inside Oracle to permit multiple sessions to work in the same transaction.  So it would be possible to have Java and C++ sessions participating in the same transaction without needing any sort of additional coordinator.  </p>\n\n<p>Alternately, you might consider using Workspace Manager.  That was originally designed to support extremely long-running transactions (i.e. manipulating lots of spatial data for a proposed development).  Essentially, you can create a workspace, which in your case would be roughly equivalent to a named transaction.  Both the Java and C++ code could enter that workspace (from separate sessions) and both could manipulate and commit data in that workspace.  When the transaction was complete, you could then merge the workspace to the LIVE workspace, which is equivalent to doing a commit in a normal transaction.</p>\n\n<p>On the other hand, I would strongly agree with your initial assessment that coordinating transactions between processes is very likely to be a bad idea from a performance, stability, simplicity, and maintenance standpoint.  On the other hand, it may well be a legitimate business requirement depending on how the C++ code is going to be retired (i.e. whether it is possible to replace code in such a way that transactions can be either exclusively Java or exclusively C++)</p>\n'}, {'answer_id': 122702, 'author': 'skaffman', 'author_id': 21234, 'author_profile': 'https://Stackoverflow.com/users/21234', 'pm_score': 0, 'selected': False, 'text': '<p>I believe JBoss Transaction Manager supports 2pc tx propagation across web service calls.  You could, I suppose integrate your systems that way, but the performance would stink.</p>\n'}, {'answer_id': 29487446, 'author': 'oluies', 'author_id': 203968, 'author_profile': 'https://Stackoverflow.com/users/203968', 'pm_score': 2, 'selected': False, 'text': '<p>I have been using <a href="http://hazelcast.com/" rel="nofollow">Hazlecast</a> Messaging and Distributed memory locks to solve some of these concerns, however using such a tool would require that you  redisign your software in those parts where you touch the same data. C++ client docs <a href="http://docs.hazelcast.org/docs/latest/manual/html/cplusclient.html" rel="nofollow">here</a> Java client <a href="http://docs.hazelcast.org/docs/latest/manual/html/javaclient.html" rel="nofollow">here</a></p>\n\n<p>Oracle also has a similar product called Oracle Coherence that may help you, see <a href="http://docs.oracle.com/cd/E18686_01/coh.37/e18677/api_transactionslocks.htm#COHDG109" rel="nofollow">locking</a> in the dev guide.  </p>\n\n<p>Also the database contains a MQ system called  <a href="http://docs.oracle.com/cd/E11882_01/server.112/e11013/aq_intro.htm#ADQUE0100" rel="nofollow">Oracle Streams Advanced queueing</a> ( transactional persistent queues) that might help you in some situations. Oracle AQ integrates well with Oracle triggers. </p>\n\n<p>Additionally there is the <a href="http://docs.oracle.com/cd/B19306_01/appdev.102/b14251/adfns_dcn.htm" rel="nofollow">Database Change Notification</a> that may help you update caches or notify processes of updates, this can be used together with the <a href="http://martinfowler.com/eaaCatalog/optimisticOfflineLock.html" rel="nofollow">Optimistic Offline Lock pattern</a>. </p>\n\n<p>See also <a href="http://en.wikipedia.org/wiki/Software_transactional_memory" rel="nofollow">Software transactional memory</a> </p>\n\n<p>Apache Zookeeper can also help you with distributed <a href="http://zookeeper.apache.org/doc/trunk/recipes.html#sc_recipes_twoPhasedCommit" rel="nofollow">locking</a>. </p>\n'}]
['https://Stackoverflow.com/questions/44005', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1809/']