'Spring. How exception translation works?

I have following code:

@Repository
public class UserDAOImpl implements UserDAO {
    public void addUser(User user) {
        throw new HibernateException("unchecked exception");
    }
}

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDAO userDAO;

    @Override
    public void addUser(User user) {
        try {
            userDAO.addUser(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

web.xml:

<context:component-scan base-package="org.example.dao,
                                      org.example.services"/>
<mvc:annotation-driven />
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>

Is it enough to translate exception? Should I to implement custom translator?

It would be nice to get example code.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source