# Intercepting Sql parameters before sql gets executed

**URL:** <https://discourse.hibernate.org/t/intercepting-sql-parameters-before-sql-gets-executed/10907>\
**Category:** Hibernate ORM\
**Created:** [January 20, 2025, 8:14am UTC](https://discourse.hibernate.org/t/intercepting-sql-parameters-before-sql-gets-executed/10907 "2025-01-20T08:14:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akansha\_Pandey](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/akansha_pandey/32/3779_2.png) [@Akansha\_Pandey](https://discourse.hibernate.org/u/Akansha_Pandey)\
**Post date:** [January 20, 2025, 8:14am UTC](https://discourse.hibernate.org/t/intercepting-sql-parameters-before-sql-gets-executed/10907/1 "2025-01-20T08:14:10Z")

</div>

Hello  
I have recently implemented Encryption decryption of some user data via Hiberate EmptyInterceptor  
in which i encrypted the values with the help of methods like onSave and onFlushDirty and decrypted the values via onLoad method

Now I am stuck at one case  
Suppose I have a table USER with fields NAME, CONTACT\_NUMBER,EMAIL

while saving the user I encrypted email and contact number

now I want to issue the following query : select \* from user where contact\_number = 123456789;

problem is my query is bringing no result because contact\_number is encrypted in database and my query param is plain.

So I want to know a way through which I can encrypt the query params  
I have used @Convert(converter = EncryptionConverter.class) this annotation but the problem is not all fields are encrypted and i want to know the entity name and field name to understand if i have to encrypt before sending it to db

Is there a way i cn make it centralised like i did encryption decryption with EmptyInterceptor

PS : kindly dont suggest inspect or onPreparedStatement of hibernate interceptor as query params are not accessbible in them. Query params comes as place holder (?)

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [January 20, 2025, 3:14pm UTC](https://discourse.hibernate.org/t/intercepting-sql-parameters-before-sql-gets-executed/10907/2 "2025-01-20T15:14:54Z")

</div>

Using a converter is your best option. You could try to ease the pain by introducing a special wrapper type e.g. `EncryptedString` and enable auto-apply for the conversion via `@Converter(autoApply = true)`.
