Hi, I am writing to ask for advice. I have 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
+1
A:
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.
BalusC
2010-06-30 22:02:23
Thank you for your answers.I have to add some details. WebApp uses JDBC. DB MySql.I would to know when some new data are inserted (insert made from third-party app inaccessible to me), because I have to send email alert for new data, so that the user can then view it in the webapp.So I defined a Thread in ServletContextListener, that periodically checks to see if there are changes in DB, extracting the latest data(max timestamp), and check with a temp table(which contains data read from the last time) if the data is old or new.Thanks much.
sangi
2010-07-01 11:17:12
@sangi - In StackOverflow, it is a good practice to take your details and put them in your question. Also, it sounds like you solved your problem, so it would help if you gave your solution as an answer. I see that you are new, so I thought I would point that out.
sheepsimulator
2010-07-01 13:29:57