ÇÁ·Î±×·¡¹Ö
ù ÆäÀÌÁö ·£´ý ±Û ȸ¿ø°¡ÀÔ ·Î±×ÀÎ
ºñ°ø°³ ¼Õ´Ô ¡¦ 2016-02-03 14:41:15
URL https://te31.com/rgr/view.php?id=study&no=1683 ¸ð¹ÙÀÏ È­¸é
Spring Æ®·£Àè¼Ç ¾î³ëÅ×ÀÌ¼Ç °í¼ö´Ôµé Áú¹®ÀÔ´Ï´Ù

¾È³çÇϼ¼¿ä. Spring 3.0 ¾²°í ÀÖ°í Æ®·£Àè¼Ç ¾î³ëÅ×À̼ÇÀ» ÀÌ¿ëÇؼ­ Æ®·£Àè¼ÇÀ» °É·Á°í Çϴµ¥¿ä.

@Service Ŭ·¡½º¿¡¼­ ¾Æ·¡¿Í °°ÀÌ ¸Þ¼Òµå¿¡ Æ®·£Àè¼Ç ¾î³ëÅ×À̼ÇÀ» ¼±¾ðÇÏ¿´½À´Ï´Ù.

@Transactional
@Override
public void insertUserStpltAgreeMgt(String userId, String clauseCode, String ipAddr)
   throws SbcApiServiceException {
  try {
   HashMap<String, Object> params = new HashMap<String, Object>();
   params.put("userId", userId);
   params.put("cretIpadr", ipAddr);
   params.put("amdIpadr", ipAddr);
   params.put("agreeYn", "Y");
   String[] codes = clauseCode.split(",");
   for(String s : codes) {
    params.put("stpltCd", s);
    iUserStpltAgreeMgtDao.insertUserStpltAgreeMgt(params);
   throw new SbcApiServiceException("test", null, SbcException.DB_ERROR);
   }
  } catch (SQLException e) {
   throw new SbcApiServiceException(e.getMessage(), e, SbcException.DB_ERROR);
  }
}

for ¹®À» 6¹øÁ¤µµ µ¹°Ô µÇ´Âµ¥ ù¹ø° for¹® µ¹°í Exception ¹ß»ý½ÃÄ×À»¶§,
Æ®·£Àè¼ÇÀÌ Á¦´ë·Î °É·ÁÀÖÀ¸¸é ¾Õ¼­ insert ¹®¿¡¼­ µé¾î°£ µ¥ÀÌÅÍ°¡ roll back µÇ¾î¾ß Çϴµ¥ roll back ÁøÇàÀÌ µÇÁö ¾Ê´õ¶ó°í¿ä;

servlet.xml ÂÊ ¼³Á¤Àº ¾Æ·¡¿Í °°ÀÌ Ãß°¡ÇÏ¿´½À´Ï´Ù.

       <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
             <property name="dataSource" ref="dataSource"/>
      

       <tx:annotation-driven transaction-manager="transactionManager" />

Æ®·£Àè¼Ç ¾î³ëÅ×À̼ÇÀ» »ç¿ëÇϱâ À§ÇØ Á¦°¡ Ãß°¡·Î È®ÀÎÇغÁ¾ß ÇÏ´Â°Ô ¾î¶²°ÍÀÌ ÀÖ´ÂÁö ¾Ë°í½Í½À´Ï´Ù.

ÀÌ¿Í º°µµ·Î ibatis Æ®·£Àè¼ÇÀ» »ç¿ëÇÏ¿´À»¶§´Â Á¤»óµ¿ÀÛÀ» È®ÀÎÇÏ¿´½À´Ï´Ù.
¾Æ·¡¿Í °°Àº °æ¿ì exception ¹ß»ý ½Ã ¾Õ¼­ insert µÈ µ¥ÀÌÅÍ°¡ rollback µÇ´Â°ÍÀ» È®ÀÎ.
  SqlMapClient client = gen.session();
  try {
   HashMap<String, Object> params = new HashMap<String, Object>();
   params.put("userId", userId);
   params.put("cretIpadr", ipAddr);
   params.put("amdIpadr", ipAddr);
   params.put("agreeYn", "Y");
   String[] codes = clauseCode.split(",");
  
   client.startTransaction();
   client.startBatch();
  
   for(String s : codes) {
    params.put("stpltCd", s);
    iUserStpltAgreeMgtDao.insertUserStpltAgreeMgt(params);
    throw new SQLException("");
   }
   client.executeBatch();
   client.commitTransaction();
  } catch (SQLException e) {
   try {
    client.endTransaction();
   } catch (SQLException e1) {
    e1.printStackTrace();
   }
   throw new SbcApiServiceException(e.getMessage(), e, SbcException.DB_ERROR);
  }

* ¾î³ëÅ×ÀÌ¼Ç ¿É¼ÇÀ¸·Î ¾Æ·¡¿Í°°ÀÌ Çغ¸¾Æµµ ¶È°°ÀÌ ·Ñ¹éÀÌ ¾ÈµË´Ï´Ù..
@Transactional(rollbackFor=SbcApiServiceException.class)
@Transactional(rollbackFor={SbcApiServiceException.class})

Áú¹® | 1765¸íÀÌ Àоú¾î¿ä. 3.145.38.117

0
1 ºñ°ø°³ ¼Õ´Ô ¡¦ 2016-02-03 21:37:09
ÀÏ´Ü ÄÚµå»óÀ¸·Î endTransaction Àº finally ¿¡¼­ ÇÏ´Â°Ô ¸Â±¸¿©.. ¿Ö³Ä¸é Áö±Ý ÄÚµå»óÀ¸·Ð SQLException ¿ÜÀÇ Throwable ÀÌ ¹ß»ýÇϸé endTransaction À» ¿µ¿µ È£ÃâÇÏÁö ¾Ê´Â ±¸Á¶¶ó¼­¸®..

±×¸®°í annotation ¹®Á¦´Â

http://stackoverflow.com/questions/10019426/spring-transactional-not-working

ÀÌ°É Âü°íÇϼ¼¿ä.
2 ºñ°ø°³ ¼Õ´Ô ¡¦ 2016-02-03 21:37:54
http://stackoverflow.com/questions/25910350/spring-transactional-is-not-working

¿ä°Íµµ¿ä
3 ºñ°ø°³ ¼Õ´Ô ¡¦ 2016-02-04 00:11:07
1,2// ´äº¯ °¨»çµå¸³´Ï´Ù. ¾Ë·ÁÁֽŠURL Âü°íÇؼ­ ´Ù½Ã Àû¿ëÇغ¸°Ú½À´Ï´Ù.
´ñ±ÛÀ» ÀÛ¼ºÇÏ½Ç ¼ö ¾ø½À´Ï´Ù.
(±ÇÇÑÀÌ ¾ø´Â ȸ¿ø·¹º§)
¸ñ·ÏÀ¸·Î
ÀÌ¿ë¾à°ü | ±¤°í/Á¦ÈÞ | °³ÀÎÁ¤º¸Ãë±Þ¹æħ | ¹®ÀÇ/½Å°í | ¸ð¹ÙÀÏ TE31 | ¼­¹ö ºÎÇÏ : 16.25%
½Ç½Ã°£ Issue Ä¿¹Â´ÏƼ TE31 [¾ËÁö·Õ] ¨Ï 2002-2024
TOP arrow_upward