# How to return SQL error Message

**URL:** <https://discourse.hibernate.org/t/how-to-return-sql-error-message/3484>\
**Category:** Hibernate ORM\
**Created:** [November 29, 2019, 6:39am UTC](https://discourse.hibernate.org/t/how-to-return-sql-error-message/3484 "2019-11-29T06:39:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pelayo](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@Pelayo](https://discourse.hibernate.org/u/Pelayo)\
**Post date:** [November 29, 2019, 6:39am UTC](https://discourse.hibernate.org/t/how-to-return-sql-error-message/3484/1 "2019-11-29T06:39:26Z")

</div>

I am a new hibernate java programmer. I have developed a small application with PostgreSQL. My problem is that when I try to delete a record used through a foreign key, the exception message just say “Could not execute statement”. I noticed in the console window that much more information is sent such as :  
org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-1) ERROR: update or delete on table “AdminSite” violates foreign key constraint “FK\_AdminUserSite” on table “AdminUserProfile”  
Detail: Key (STCode)=(HO ) is still referenced from table “AdminUserProfile”.

I want to retrieve and display this message. How can it be made as it is not an exception ?
