Logic: Database or Application/2 (constraints check)
This is a specific version of this question . I want to check if I am inserting a duplicate row. Should I check it programmatically in my application layer: if (exists(obj)) { throw new DuplicateObjectException(); } HibernateSessionFactory.getSession().save(obj); or should I catch the exception thrown by the database layer and triggered when I violate the contraint? try { HibernateSessionFactory.getSession().save(obj); } catch(ConstraintViolationException e) { throw new DuplicateObjectException(); } EDIT: In other words: though the constraint is there to remain (it's good database design