首先说下目的。在表A中有个tree_code 字段,要往这个表A插入新记录的时候。需要先查一下tree_code的最大值,然后+1 后作为新的记录的tree_code值。这样在多人同时操作的时候,就会出现tree_code值相同的情况。所以我这里想利用Spring2.0的AOP事务来处理这种情况。
我在Spring中是这么定义的:
<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="add*"  propagation="REQUIRES"  isolation="SERIALIZABLE" />
    </tx:attributes>
</tx:advice>

<aop:config>
   <aop:pointcut id="gameInfoDaopointcut"
       expression="execution(* com.extjsdemo.gameinfo.manager.IGameInfoManger.*(..))" />
       <aop:advisor advice-ref="txAdvice" pointcut-ref="gameInfoDaopointcut" />
</aop:config>
我这里就是想让IGameInfoManger中的已add开头的方法进行隔离,我都已经用了最严格的隔离方式了“SERIALIZABLE”。但是数据库中还是会有相同的tree_code记录,请帮我搞搞这个问题。IGameInfoManger的具体实现如下:public class GameInfoManager implements IGameInfoManger {

private IGameInfoDao gameInfoDao; @Override
public List<GcmGameinfo> getAllGameInfos() {
return this.gameInfoDao.getAllGameInfos();
}

@Override
public String getMaxTreeCode() {
return this.gameInfoDao.getMaxTreeCode();
} @Override
public void insertGameInfo(GcmGameinfo gameinfo) {
this.gameInfoDao.insertGameInfo(gameinfo);
}
@Override
public void addOneGameInfo(GcmGameinfo gameinfo) {
String maxTreeCode = this.getMaxTreeCode();
int newInt = (Integer.parseInt(maxTreeCode)+1);
String newMaxTreeCode = ("0000" + newInt).substring(String.valueOf(newInt).length());
gameinfo.setTreeCode(newMaxTreeCode);
this.insertGameInfo(gameinfo);
} @Override
public void saveGameInfo(GcmGameinfo gameinfo) {
this.gameInfoDao.saveGameInfo(gameinfo);
} public IGameInfoDao getGameInfoDao() {
return gameInfoDao;
} public void setGameInfoDao(IGameInfoDao gameInfoDao) {
this.gameInfoDao = gameInfoDao;
}}