diff --git a/jpetstore/src/org/springframework/samples/jpetstore/dao/ibatis/SqlMapSequenceDao.java b/jpetstore/src/org/springframework/samples/jpetstore/dao/ibatis/SqlMapSequenceDao.java index bf0e7d1..d5e2e54 100644 --- a/jpetstore/src/org/springframework/samples/jpetstore/dao/ibatis/SqlMapSequenceDao.java +++ b/jpetstore/src/org/springframework/samples/jpetstore/dao/ibatis/SqlMapSequenceDao.java @@ -15,14 +15,13 @@ public class SqlMapSequenceDao extends SqlMapClientDaoSupport { */ public int getNextId(String name) throws DataAccessException { Sequence sequence = new Sequence(name, -1); - sequence = (Sequence) getSqlMapClientTemplate().queryForObject("getSequence", sequence); + sequence = (Sequence) getSqlMapClientTemplate().queryForObject("incrementAndReturnModified", sequence); if (sequence == null) { throw new DataRetrievalFailureException( - "Could not get next value of sequence '" + name + "': sequence does not exist"); + "Could not get next value of sequence '" + name + "': sequence does not exist"); } - Object parameterObject = new Sequence(name, sequence.getNextId() + 1); - getSqlMapClientTemplate().update("updateSequence", parameterObject, 1); return sequence.getNextId(); } } + diff --git a/jpetstore/src/org/springframework/samples/jpetstore/dao/ibatis/maps/Sequence.xml b/jpetstore/src/org/springframework/samples/jpetstore/dao/ibatis/maps/Sequence.xml index 8c6dbe9..e8d4870 100644 --- a/jpetstore/src/org/springframework/samples/jpetstore/dao/ibatis/maps/Sequence.xml +++ b/jpetstore/src/org/springframework/samples/jpetstore/dao/ibatis/maps/Sequence.xml @@ -20,4 +20,9 @@ update sequence set nextid = #nextId# where name = #name# + + +