onesixtyfourth
onesixtyfourth

Reputation: 866

processing from a entity constructor

I haven't tried this yet as I am still sorting out my entities but my question is:

I have an entity that will require to do some processing on a value once it has been loaded. My first thought is that I could call a method from the constructor but I can't help thinking this won't work as the object will need to be constructed before the set methods can be called.

Do I have to create a method to do the processing and call it when I need it or is there a way to do some processing auto magically as it is created by jpa?

Upvotes: 0

Views: 38

Answers (1)

JB Nizet
JB Nizet

Reputation: 691755

You can annotate a method of your entity class, not taking any argument, and returning void, with @PostLoad. The specification says:

The PostLoad method for an entity is invoked after the entity has been loaded into the current persis- tence context from the database or after the refresh operation has been applied to it. The PostLoad method is invoked before a query result is returned or accessed or before an association is traversed.

Upvotes: 1

Related Questions