开发者

PostLoad method is not being called on an Id class

开发者 https://www.devze.com 2023-01-14 18:18 出处:网络
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.

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号