Announcement Announcement Module
Collapse
No announcement yet.
org.springframework.dao.DataAccessException cast to user define exceptions. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • org.springframework.dao.DataAccessException cast to user define exceptions.

    Currently I am using Spring>>Hibernate>>MySQL for my data layer. when I get any sql error, it wraps with Spring Generic DataAccessException. I want to give meaningful error messages to user base on the Spring Data Exception.

    Can any body suggest, what is the best way to map Spring DataAccessExceptions to diffrent User Define error messages ?

    Eg: based on the following exception log,how we justify this is Primary Key Violation, If we had JDBCException, we can refer to the SQLErrorcode and map custom Error message to user.

    org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; SQL [insert into Vehicle (vehicle_name, owner, remarks, next_license_date, next_insurance_date, inserted_date, updated_date, userid, vehicle_reg_no) values (?, ?, ?, ?, ?, ?, ?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationExcepti on: Could not execute JDBC batch update
    at org.springframework.orm.hibernate3.SessionFactoryU tils.convertHibernateAccessException(SessionFactor yUtils.java:643)
    at org.springframework.orm.hibernate3.HibernateTransa ctionManager.convertHibernateAccessException(Hiber nateTransactionManager.java:793)
    at org.springframework.orm.hibernate3.HibernateTransa ctionManager.doCommit(HibernateTransactionManager. java:664)
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.processCommit(AbstractPla tformTransactionManager.java:754)
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.commit(AbstractPlatformTr ansactionManager.java:723)
    at org.springframework.transaction.interceptor.Transa ctionAspectSupport.commitTransactionAfterReturning (TransactionAspectSupport.java:392)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:120)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172)
    at org.springframework.aop.framework.CglibAopProxy$Dy namicAdvisedInterceptor.intercept(CglibAopProxy.ja va:631)
    at com.shan.ebusiness.manager.VehicleManager$$Enhance rByCGLIB$$a79c4552.saveVehicle(<generated>)
    at com.shan.ebusiness.web.controller.VehicleControlle r.addVehicle(VehicleController.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    Last edited by kushanme; May 20th, 2014, 03:49 AM. Reason: Spring Dao, Hibernate
Working...
X