shadowek
Aug 13th, 2004, 05:05 PM
Hi guys,
My DAO has the following methods:
boolean isAccountExist(Account account);//check if specified account exist in database
void createAccount(Account account); //save the specified Account object via saveOrUpdate
In the service layer I would like to have method creating a new account but only when the account doesn't exist yet; something like that:
public void createAccountService(Account account)
{
if(!dao.isAccountExist(account))
{
//***1***
//other user can create the same account(with the same login name)
dao.createAccount(account);
}
}
The question is:how can I guarantee that between checking if account exist and creating the account in database (the ***1*** line in the above code snippet), no one create the same account (with the same login name)? I know that I must use transaction, but could you explicite show me how to configure it, please?
My DAO has the following methods:
boolean isAccountExist(Account account);//check if specified account exist in database
void createAccount(Account account); //save the specified Account object via saveOrUpdate
In the service layer I would like to have method creating a new account but only when the account doesn't exist yet; something like that:
public void createAccountService(Account account)
{
if(!dao.isAccountExist(account))
{
//***1***
//other user can create the same account(with the same login name)
dao.createAccount(account);
}
}
The question is:how can I guarantee that between checking if account exist and creating the account in database (the ***1*** line in the above code snippet), no one create the same account (with the same login name)? I know that I must use transaction, but could you explicite show me how to configure it, please?