简体   繁体   中英

Is there an Annotation for method, to work as a trigger in Java Spring?

I would like to execute certain method every time a specific Entity is persisted. This method should perform some kind of checking on entity object, so its need a access to this specific object.

Is there an Annotation, or other method allowing me to do so? Basically, it should be working like some kind of trigger.

does after point cut of spring aop can solve your problem?

You could consider using entity validation annotations directly on your entity objects, eg hibernate entity annotations. If you register your entity validator, these can be called automatically prior to entity save.

I think you are looking for this

https://www.baeldung.com/jpa-entity-lifecycle-events

So you can use @PostPersist inside your entity

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM