views:

23

answers:

1

I have an entity class and another class is Identity class of this entity. I have written @javax.persistence.PostLoad annotation in Id class to put some default value on one of the column.

But I found out that it is not being called at all. Is it that ID classes should not have this annotation?

+2  A: 

you can annotate a method in you Entity class by @PostLoad to set default value to ...

if you annotate you ID class, then you need to introduce it as Callback Listener in your Entity class :

@EntityListeners({ID.class})
class MyEntity

and i don't think its a good idea, because the instance of your Listener is not related to the Instance of ID in your Entity class. they are 2 different object of ID class.

@PostLoad

Is used to specify callback methods for the corresponding lifecycle event. This annotation may be applied to methods of an entity class, a mapped superclass, or a callback listener class.

mohammad shamsi
Thank you mohammad. My mistake, just I am about to post the same. It was resolved by moving the @PostLoad to the Entity class instead of identity class.
Reddy