1

I am new to Hibernate. I have a use case where I need to apply a transformer (encrypt/encode) on the persistent class member just before it is saved and (decrypt/decode) after the data is loaded. What I am looking at is something like this:

public class PersistentClass {

    @Encrypt(transformer=DoubleTransformer)
    public Double dataToBeEncoded;

    public Double persistAsIs;
}

All my transformers result in text data that will be persisted in db and I want to define transformers once and reuse it in all the persistent classes. Is there an easy way to do this?

raggy
  • 59
  • 1
  • 5

1 Answers1

2

Yes, there is: JPA life cycle callbacks, or Hibernate inerceptors. Just implement the Pre-Persist, Pre-Update and Post-Load listeners.

Dragan Bozanovic
  • 23,102
  • 5
  • 43
  • 110