# How to get Exception from unique constraint

**URL:** <https://discourse.hibernate.org/t/how-to-get-exception-from-unique-constraint/3027>\
**Category:** Hibernate ORM\
**Created:** [July 29, 2019, 12:24pm UTC](https://discourse.hibernate.org/t/how-to-get-exception-from-unique-constraint/3027 "2019-07-29T12:24:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![siedmohsen2](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/siedmohsen2/32/737_2.png) [@siedmohsen2](https://discourse.hibernate.org/u/siedmohsen2)\
**Post date:** [July 29, 2019, 12:24pm UTC](https://discourse.hibernate.org/t/how-to-get-exception-from-unique-constraint/3027/1 "2019-07-29T12:24:25Z")

</div>

Hi  
I use hibernate 5.2.10 & spring boot 2.1.1 & JTA & Weblogic 12.2.2.1  
Now when we save any entity that has some constraint such as unique constraint & foreign key constraint … we get error but we could not get clear Exception in our back-end. Because our Exception catch in ResultSetReturnImpl and the result print with SqlExceptionHelper, so we could not catch those exception!!  
My code is

```auto
public viod add (T entity){
Session session = getSession();
try{
    session.save(entity);
}catch (TransactionException ex){
   System.out.println("++++++++"); // Do Not go here when throw exception for unique constraint
}
}

```

So we could not find any answer for this problem!  
Is there any answer??  
Could we override ResultSetReturnImpl and customize this method?

---

<div class="post-metadata">

**Author:** ![siedmohsen2](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/siedmohsen2/32/737_2.png) [@siedmohsen2](https://discourse.hibernate.org/u/siedmohsen2)\
**Post date:** [August 13, 2019, 6:16pm UTC](https://discourse.hibernate.org/t/how-to-get-exception-from-unique-constraint/3027/2 "2019-08-13T18:16:46Z")

</div>

I found answer!!!  
It’s in spring configuration. I always use JTA for manage my transaction but should be use from JPA transaction for solve this issue.Like [This](https://www.baeldung.com/transaction-configuration-with-jpa-and-spring)

thank’s all
