Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8727465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:26:20+00:00 2026-06-13T08:26:20+00:00

There is a code like this: ATransaction.commit (); BTransaction.commit (); Both transactions are working

  • 0

There is a code like this:

ATransaction.commit ();
BTransaction.commit ();

Both transactions are working with different schemes (ie persistence-unit they are different). It is necessary to combine both in one transaction. So if any one transaction fails to rollback both. How to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:26:21+00:00Added an answer on June 13, 2026 at 8:26 am

    It seems like you are managing transactions yourself. Typically the Java EE container would handle such cases for you. JTA uses two-phase commits in this case which is exactly for situations like this.

    If your are managing transactions yourself, it is a bit more complicated. The problem is that if you commit the first and the commit of the second one fails, you cannot rollback the first any more.

    In your case I suggest the follwing. Typically a commit can only fail, because the Hibernate doesn’t immediately write changes to the database if you modify an object. This happens when Hibernate performs a “flush”. This is done automatically before queries are executed which may be affected by objects you already modified and also before the transaction is committed.

    So you could simply flush both entity managers first, which will write all the changes to both databases, and then commit both transaction, which shouldn’t fail anymore.

    Something like this:

    entityManager1.flush();
    entityManager2.flush();
    entityManager1.getTransaction().commit();
    entityManager2.getTransaction().commit();
    

    However I recommend to don’t manage such cases manually and instead let the container do this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just found my code like this does not compile right? Is there any
I have some code that looks like this. There is also an autoincrement field
I have code which needs to do something like this There is a list
In my code there are a lot of final values, like 10000. They never
I want to know why the three.js code is structured like this: THREE.Camera =
In my application there is language detection. Languages have some identification code like en
I would like to start making code patches to Rails. Are there any good
Is there any way to execute arbitrary code in Flash, like javascript's eval()? I'd
Is there any online complier/interpreter to execute code for php 5.3? like there is
Is there any way to achieve compiling Node.js scripts as native code, like Hip-Hop

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.