0

I need help with my project since I am not familiar with the spring @transactional annotation. The question is why my application hungs up using the @transactional method but will not hung up without it. Also how do I solve this so that the transaction will suceed.

The scenario is that my application is set-up like this:

  1. Uses declarative transaction Management
  2. One method has the @transactional(rollbackFor=Exception.class) annotation and accesses the database multiple times.
  3. The said method calls another method that returns a String and accesses the database multiple times.
  4. Transaction does not suceed finishing causes a deadlock on my application. It does not return any exception.

The Code below is sample snippet

 @Autowired
 JdbcTemplate template;

 @Transactional(rollbackFor = Exception.class)
  public final void upsertData(){
  insertTable1(); // insert query to insert in table 1
  addReferencingData(); // was just called to update table but returns                something which is not used;
  //Hangs up before getting to next statement
  somePreparedStatmentSQLmergeTable1(mergesql,template); // query to merge in table 1
}

public final String addReferencingData(){
   updateTableA(); // update query to update values in table A
   updateTableB(); // update query to update values in table B
   mergeTable1(); // merge query to update or insert in table 1

  return someString;
}

    public static void somePreparedStatmentSQLmergeTable1(sql,template){
      template.batchUpdate(sql, new BatchPreparedStatementSetter() {

        public void setValues(final PreparedStatement ps, final int i){
         // setting parameters to be used
         }
         public int getBatchSize(){
         // returns size of data's
         }
      }
    }

Also added the default Transaction manager on my application-context.xml file.Transaction already works based on logs. Only in this specific method it does not work.

Updated some information to be clearer.

  • What happens if you exclude `mergeTable1();` call? – StanislavL Dec 08 '17 at 07:32
  • read this https://stackoverflow.com/questions/1099025/spring-transactional-what-happens-in-background – Amol Raje Dec 08 '17 at 07:38
  • 1
    And you expect us to guess everything you do in your `insertTable1()`, `somePreparedStatementSQL` methods? Add the implementation? Generally if your application stops that is due to the fact that you are messing around with things in a wrong way (like obtaining a connection yourself instead of using the `JdbcTemplate` properly). – M. Deinum Dec 08 '17 at 08:04
  • Hi sorry, No that is not my intention, I have just used general terms because I can't divulge too much information due to the nature of my job. but those methods are actually mapped queries that does as it is stated. A PreparedStatementSQL and some Merge, Update and Insert Queries. But I do agree with you it is a fact that I may be using some things which they are not intended for. – Jann Mervin Arenas Dec 08 '17 at 08:56
  • @StanislavL, It still does not work, Thanks for suggesting – Jann Mervin Arenas Dec 08 '17 at 09:31
  • @AmolRaje Thanks for the information will read about it – Jann Mervin Arenas Dec 08 '17 at 09:31

0 Answers0