spring-projects / spring-data-r2dbc

Provide support to increase developer productivity in Java when using Reactive Relational Database Connectivity. Uses familiar Spring concepts such as a DatabaseClient for core API usage and lightweight repository style data access.
Apache License 2.0
708 stars 132 forks source link

Model entity need to add custom Encryption on insert/update and decrypt on read #839

Open sandeep2244 opened 11 months ago

sandeep2244 commented 11 months ago

Hello,

Can you guys define how to implement encryption, decryption on some of Model columns by custom annotation. Or any eventListener such as Hibernate in R2DBC can use ? We can find solution for JPA but not found for R2DBC.

mp911de commented 11 months ago

There's no consistent way to post-process database values before writing them to the database or after returning these and before conversion into an entity.

sandeep2244 commented 11 months ago

@mp911de does customConverter works with this requirement ? I mean just need to verify that, it won't make any issue to persist DB value, state right ?

mp911de commented 11 months ago

CustomConversions uses type-based converters to e.g. apply conversion for temporal types or to serialize a custom type to bytes or JSON. We do not have sufficient hooks. While there's a BeforeSave callback, there's no way to post-process the loaded result when reading or when running a query.

sandeep2244 commented 11 months ago

Sounds good @mp911de , I checked BeforeSaveCallback is of type based conversion at table level. May I know , does it work for annotation on Column based ?, requirement is to add encryption for some of the columns only.