SHARE
TWEET

Untitled

a guest Jun 18th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Transactional
  2. public boolean generateLogsComposite() {
  3.     Connection conn = getConnection();
  4.     writeSomeData(conn);//write some data using a separate connection
  5.     boolean isNew = checkSomeData();//The check works with the data from writeSomeData although not using he connection conn
  6.     if(isNew) {
  7.         generateEmail(conn);//Calls a stored procedure on connection conn.
  8.         updateRunEnvOnEmail(emailId, runEnv);
  9.         //Now the data from generateEmail and updateRunEnvOnEmail is present
  10.     } else {
  11.         updateSomething();//has a javax.persistence.TransactionRequiredException: Executing an update/delete query
  12.     }
  13. }
  14.  
  15. private void joinTransaction() {
  16.     try {
  17.         //HACK vs javax.persistence.TransactionRequiredException: Executing an update/delete query
  18.         entityManager.joinTransaction();
  19.         logger.debug("Joined transaction successfully");
  20.     } catch(Throwable t) {
  21.         //java.lang.IllegalStateException: Not allowed to join transaction on shared EntityManager
  22.     }
  23. }
  24.  
  25. @Transactional
  26. public void updateRunEnvOnEmail(Long emailId, String runEnv)
  27. {
  28.     try
  29.     {
  30.         //HACK vs javax.persistence.TransactionRequiredException: Executing an update/delete query
  31.         joinTransaction();
  32.  
  33.         Query query = entityManager
  34.                 .createNativeQuery("update XXX.EMAIL e set e.RUN_ENVIRONMENT = :runEnv where e.EMAIL_ID = :emailId");
  35.         query.setParameter("runEnv", runEnv);
  36.         query.setParameter("emailId", emailId);
  37.         query.executeUpdate();
  38.     } catch (Exception e)
  39.     {
  40.         logger.debug("Error while updating RUN_ENVIRONMENT on Email : "
  41.                 + emailId + " ::: " + e);
  42.     }
  43.  
  44. }
  45.  
  46. @Transactional
  47. public void updateSomething()
  48. {
  49.     try
  50.     {
  51.         //HACK vs javax.persistence.TransactionRequiredException: Executing an update/delete query
  52.         joinTransaction();
  53.  
  54.         Query query = entityManager
  55.                 .createNativeQuery("update something");
  56.         query.executeUpdate();
  57.     } catch (Exception e)
  58.     {
  59.         logger.debug("Error while updating something",e);
  60.     }
  61.  
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top