It appears you sent this to the wrong list. On 11/15/06, Man-Chi Leung <[EMAIL PROTECTED]> wrote:
hi,in appfuse's User schema: email column is declared as unique in xdoclet-hibernate tag. therefore, no repeated email is allowed, or else hibernate will throw ConstraintViolationException, then Spring will rewrap it as DataIntegrityViolationException. I wrote a test case as the following and it is passed successfully by catching Spring's DataIntegrityViolationException. My question: what is the best pracitice to handle this? 1) AJAX Level: very likely, I am going to do a validation manager via DWR, when user keys in the email text field, there is a response on "repeated email error" instantly. 2) Action Level: to be safe, i will validate again at action level before passing to service layer. 3) DAO Level: one more validation for repeated email before finally calling dao.saveUser(user2); yes, it is too much. how can I make my life easier? any shortcut that I missed out ? .... I am puzzled on how others are doing for this. PLS help! (sorry for my ignorance) thanks to appfuse community ~thinkboy ===UserDaoTest.java=== public void testUpdateUserWithRepeatedEmail() throws Exception { User user1 = dao.getUser(new Long(1)); User user2 = dao.getUser(new Long(2)); try { user2.setEmail(user1.getEmail()); dao.saveUser(user2); fail("saveUser didn't throw DataIntegrityViolationException when same email is inserted"); } catch (DataIntegrityViolationException e) { assertNotNull(e); log.debug("expected exception: " + e.getMessage()); } } ===UserHibernateDao.java=== public void saveUser(final User user) { if (log.isDebugEnabled()) { log.debug("user's id: " + user.getId()); } getHibernateTemplate().saveOrUpdate(user); getHibernateTemplate().flush(); } ===Exception Log:=== [junit] [platform] ERROR [main] JDBCExceptionReporter.logExceptions(72) | Duplicate entry '[EMAIL PROTECTED]' for key 3 [junit] [platform] ERROR [main] AbstractFlushingEventListener.performExecutions(301) | Could not synchronize database state with session [junit] org.hibernate.exception.ConstraintViolationException: could not update: [com.rosonix.platform.model.User#2] .... --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- James Stauffer http://www.geocities.com/stauffer_james/ Are you good? Take the test at http://www.livingwaters.com/good/ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
