I am writing to ask for advice. I 开发者_如何学Chave to monitor certain "insert" on a mysql db. In what way is more convenient to do this? The application uses Servlets and MySQL. Thank you very much
Depends on the persistence framework you're using.
- If it's Hibernate, you need to implement an
Interceptor
and hook ononSave()
. - If it's JPA, you need to use an entity method with the
@PrePersist
or@PostPersist
annotation. - If it's plain vanilla JDBC, just add the code to the boilerplated DAO method.
This is unrelated to servlets. The servlet is just an API for intercepting on HTTP requests. Your data access layer should be independent and transparent from that.
精彩评论