Loading the transition field of a JPA object

I have an object with a "limit" temporary field that I want to load after calculating it, applying a formula to the value of another constant "rate". How do I do this when loading an object?

+3


source to share


1 answer


You can use JPA lifecycle listeners. You can define listener callback methods inside your object or in your own class.

Since you want to filter the data coming from the DB, you must use a callback PostLoad

.



The easiest way is to add a listener method to your entity class:

  @PostLoad
  public/protected void calcLimit() {
   // calculate limit
  }

      

+4


source







All Articles