Interface with Exception extends interface without exception
Hay,
I have a User-Table with the unique field email, which serves as username. Now when i call the dao.create method twice with the same information, i get an org.springframework.dao.DataIntegrityViolationException (Duplicate entry....). This brings me to the point, where i want my userDao.create(o) to throw a checked exception. Now i have the problem, that my UserDao-Interface extends the GenericDao-Interface, which already defines the create method without the throw-clause.
Since an extending interface can't throw more exceptions than the interface which it is extending, this code doesn't compile:
public interface GenericDao<T, PK extends Serializable> {
/...
T create(T object);
/...
}
public interface UserDao extends GenericDao<User, Long> {
/...
User create(User user) throws UserExistsException;
/...
}
(For why this is the cause see: Java interface extends questions (answer from cletus))
Now my question: What is the best practice to solve this problem?
Thank you very much for your answers in advance =)
PS: So far i have come up with a couple of answers, which don't really satisfy me. For one i could let GenericDao throw a checked exception, but since aproximatly 99% of tables dont have a unique-field (other than the pk) this isn't acceptable. Making UserExistsException a Runtime-Exception and document it seams not very nice either since i want to force the user of the method to catch the exception and report it to the enduser. Creating a new userDao.createUser()-method that throws the Exeption and throwing an UnsupportedOperationException with the already existing userDao.create()-method seams to me to be the tidiest of all solutions which came to my mind so far. I still would love to know, what is the proper way to solve this problem?