thanks for tips. My question is how to make account insertion atomic in jpetstore example. Will following code makes atomic transaction?
in AccountService.java
public void insertAccount(Account account) {
try{
daoManager.startTransaction();
accountDao.insertAccount(account);
daoManager.commitTransaction();
} finally {
daoManager.endTransaction();
}
public void insertAccount(Account account) {
update("insertAccount", account);
update("insertProfile", account);
update("insertSignon", account);
}
Or we have to bring up inserting Profile and inserting Sigon to service layer . For example,
public void insertAccount(Account account) {
try{
daoManager.startTransaction();
accountDao.insertAccount(account); // DAO only inserts data to account table
profileDao.insertProfile(account); // DAO only inserts data to profile table
sigonDao.insertSignon(account); // DAO only inserts data to signon table
daoManager.commitTransaction();
} finally {
daoManager.endTransaction();
}
If we don't use daoManager and external transaction manager, how to make the transaction atomic using iBATIS in above situation?
thanks,
Tony
Jeff Butler wrote on 3/6/2006, 2:38 PM:
In iBATIS, each call is a seperate transaction unless you override it. You can override with your own transaction management (DAO or SqlMap API calls), or use an external transaction manager.The method you mention above (AccountService.insertAccount()) will result in three seperate transactions unless there is an external transaction manager. This is why it is a pretty good practice to always wrap the DAO calls in the service layer in iBATIS transaction management code. If there was an external transaction manager, that code would be ignored. If there was not an external transaction manager, then using the iBATIS transaction API would guarantee a single transaction for each service method (a good idea IMHO).So I think the jpetstore example is not really correct in this instance.BTW - I would always control transactions in the service layer, never in the DAO layer. This will work well with Abator too.Jeff Butler
On 3/6/06, Tony Qian <[EMAIL PROTECTED]> wrote:
Jean-Francois Poilpret wrote on 3/6/2006, 10:40 AM:in AccountService.java
public void insertAccount(Account account) {
accountDao.insertAccount(account);
}Thank you very much for your response. Do you know if above code guarantee an atomic transaction in iBATIS? accountDao.insertAccount(account) calls three updates (more accurately three inserts to different tables).
thanks,
Tony
