简体   繁体   中英

Convert Hibernate exceptions in Spring Roo to Spring Data Access exceptions

I am currently working on a Spring Roo project and I want the exceptions thrown by Hibernate to be converted to Spring Exceptions. Eg I want the Hibernate exception ConstraintViolationException to be converted to Spring's DataIntegrityViolationException.

I have done this in Spring projects previously by adding in the following code to my Spring config:

<!-- Translates Hibernate exceptions to Spring Data Access Exceptions -->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>

However in Roo this does not work. Can anybody tell me how I can get this working and why it doesn't work in Roo?

You must setup the persistence layer as JPA Repository in order Roo configures your project to use Spring Data.

http://docs.spring.io/spring-roo/reference/html/base-layers.html#d4e1962

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM