The exception in hibernate jpa and spring data jpa is uncheked .It throws runtime exception .
For example
public void persist(String entityName, Object object)
throws HibernateException {
firePersist(new PersistEvent(entityName, object, this));
}
public class HibernateException extends RuntimeException {
public HibernateException(String message) {
super(message);
}
public HibernateException(Throwable root) {
super(root);
}
public HibernateException(String message, Throwable root) {
super(message, root);
}
}
a
so when u call save on spring data jpa .It throws runtime exception.
@Transactional
public T save(T entity) {
if (this.entityInformation.isNew(entity)) {
this.em.persist(entity);
return entity;
}
return this.em.merge(entity);
}
So,when u call save and if you want to catch business related exception .I better to throw own checked exception declaring in interface
public User checkClientUser(Dto dto) throws Exception;
In Serviceimpl throw exception and catch from aop
No comments:
Post a Comment