Márcio
Márcio

Reputation: 57

Give another action for JPA EntityManager persist() method

I want to, when persist (maybe merge too) method is executed, he calls a procedure in DB instead of make an instance managed and persistent (original action).

It's possible?

Upvotes: 0

Views: 176

Answers (1)

Zeus
Zeus

Reputation: 6566

Use Hibernate Interceptors or Events for that case.

If you would like to only call this only on a few occasions, annotate the Entity with custom annotations. And within the newly created Interceptor use refactoring and find if the saved entity has the annotation. If annotation is present then call the desired stored procedure.

Upvotes: 1

Related Questions