Hello,
I'm really sorry to ask this basic question :
Supposing I'm checking database constraints in java code, where should I check them and where should I generate the corresponding exception :
In the Dao component or in the service component ?
Thank you very much for your advice on this matter.
For instance I have UserManager and UserDao, if I'm going to check in service, I will have :
If I'm checking it in Dao, I'll have this sample code :Code:public class UserManagerImpl implements UserManager { public void save(User User) throws DuplicatedUserNameException { if (dao.isUsernameExists(user.getName()) { throw new DuplicatedUserNameException ("Duplicate username."); } dao.save(user); } }
Code:public class UserDao implements UserDao { public void save(User User) throws DuplicatedUserNameException { User lExisiting = (User) getJpaTemplate().find (User.class, user.getId()); if (lExising != null) { throw new DuplicatedUserNameException ("Duplicate username."); } dao.save(user); } }


Reply With Quote

