if you have to encrypt data through hibernate, you can listen to save & update events by extending DefaultSaveOrUpdateListener, check this out for an example
http://www.java2s.com/Code/Java/Hibernate/EventYourOwnSaveOrUpdateEventListener.htm
you also need to add the config to your hibernate,cfg,xml file.
<listener class="" type="auto-flush" />
this will listen to all save & update events
to listen to object creation (when you load data) use the DefaultLoadListener
http://www.java2s.com/Open-Source/Java-Document/Database-ORM/hibernate/org/hibernate/event/def/DefaultLoadEventListener.java.htm
remember, these events are called only when you are using a regular session (by calling openSession()
or getSession()
, if you use session.openStatelessSession()
then these calls do not happen)