Hibernate – two different transactions will be successfully submitted

I am using two different databases. I am using two different sessions to delete records from the two databases. The code is as follows:

try{
Session session1 = factory.getSession();
Transaction trn1 = session1.beginTrn();
session1.delete(foobar);
trn1.commit();

Session session2 = jbomContext.getGrahpSession();
Transaction trn2 = session2.beginTrn();
session2.delete(box);`enter code here`
trn2.commit();
}catch(Exception e){
trn1.rollback();
trn2.rollback();
}

Here, the problem is that if an error occurs in transaction2 I cannot roll back the transaction. I have some ideas about two-phase commit. But if the exception will occur in two transactions, I need to roll back the transaction.

You cannot roll back tr1 (if tr2’s submission fails) because tr1 has already been submitted. At least I’m not in See the local way of doing this in hibernate. What you can do is to use distributed transactions (JTA data sources), if you are using a full Java EE App Server, or you can enable it by other means (such as this and Spring's JtaTransactionManager).

I am using two different databases. I am using two different sessions to delete records from the two databases. The code is as follows:

try{
Session session1 = factory.getSession();
Transaction trn1 = session1.beginT rn();
session1.delete(foobar);
trn1.commit();

Session session2 = jbomContext.getGrahpSession();
Transaction trn2 = session2 .beginTrn();
session2.delete(box);`enter code here`
trn2.commit();
}catch(Exception e){
trn1.rollback( );
trn2.rollback();
)

Here, the problem is that I cannot roll back the transaction if an error occurs in transaction2. I have some thoughts on two-phase commit. But if the exception will occur in two transactions, I need to roll back the transaction.

You cannot roll back tr1 (if the commit of tr2 fails) because tr1 has been Submitted. At least I did not see a local way of doing this in hibernate. What you can do is to use distributed transactions (JTA data source), if you are using a full Java EE App Server, or you can enable it by other means It (such as this and Spring's JtaTransactionManager).

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4457 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.