0

How can I configure hibernate event listeners "post-insert", "post-delete", "post-load", "post-update" in java configuration? Either thru annotations or using Spring IOC? Also, is there a way to configure for a specific entity rather than in the method checking instanceof?

1 Answer 1

1

You can use the JPA annotations @PostLoad, @PostPersist, @PostRemove, @PostUpdate, @PrePersist, @PreRemove, @PreUpdate in void methods without parameters inside your entity class. They will be called when the event is performed for a specific entity.

http://download.oracle.com/javaee/5/api/index.html?javax/persistence/package-summary.html

Sign up to request clarification or add additional context in comments.

4 Comments

thx. Any ideas how to use post load for the following code? opensource.atlassian.com/projects/hibernate/browse/HHH-1395 final NestedSetNode node = (NestedSetNode) event.getEntity(); node.setPreviousParent(node.getParent()); new InsertNestedSetOperation( (NestedSetNode<?>) event.getEntity()).execute(event.getSession());
You mean, other than what is discussed in that JIRA? No, sorry.
Created separate question for listener that requires session stackoverflow.com/questions/4683820/…
Warning: this only works when you access Hibernate through JPA. If you use the Hibernate Session object directly, those annotations are ignored.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.