Hi guys,
My DAO has the following methods:
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:Code:boolean isAccountExist(Account account);//check if specified account exist in database void createAccount(Account account); //save the specified Account object via saveOrUpdate
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?Code: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); } }


Reply With Quote