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:
- Uses declarative transaction Management
- One method has the @transactional(rollbackFor=Exception.class) annotation and accesses the database multiple times.
- The said method calls another method that returns a String and accesses the database multiple times.
- 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.