Announcement Announcement Module
Collapse
No announcement yet.
net.sf.hibernate.Interceptor and HibernateDaoSupport Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • net.sf.hibernate.Interceptor and HibernateDaoSupport

    I am using HibernateDaoSupport. I have written a net.sf.hibernate.Interceptor for AuditLogging. If I were using Hibernate, I would use the following code to get the session using the hibernate interceptor:

    Code:
    Session session = sf.openSession ( new AuditInterceptor() );
    Is there a way to pass in an interceptor to HibernateDaoSupport? If not, is there an alternative best way to use a Hibernate Interceptor within the confines of the hibernate support in the SpringFramework? Do I need to subclass HibernateDaoSupport to make this happen?

    Thank you for your time.

  • #2
    If you are using LocalSessionFactoryBean to configure the Hibernate SessionFactory then you can set the entityInterceptor property to an instance of net.sf.hibernate.Interceptor which will be used to construct any Sessions.

    Rob

    Comment


    • #3
      amazing!

      Thanks for the quick response. I am amazed by how fast support on this board is.

      Comment


      • #4
        issue

        If you are using LocalSessionFactoryBean to configure the Hibernate SessionFactory then you can set the entityInterceptor property to an instance of net.sf.hibernate.Interceptor which will be used to construct any Sessions.
        I tried this as the following code shows:

        Code:
                      HibernateTemplate hibernateTemplate = getHibernateTemplate();
                      
                      log.debug("Setting Interceptor");
                      try {
                          hibernateTemplate.setEntityInterceptor(new AuditInterceptor());
                      } catch (HibernateException he) {
                          log.error(he);
                      }
                      log.debug("Done Setting Interceptor");
                      
                      log.debug("Saving Product");
                      hibernateTemplate.save(product);
                      log.debug("Done Saving Product");
        I would expect that the onSave method in the AuditInterceptor would be called. It is not. Any idea what I could be doing wrong?

        Thanks,

        Ethan

        Comment


        • #5
          Ethan,

          I think you need to set the Interceptor at session level via the LocalSessionFactoryBean rather than on a case by case basis via the HibernateTemplate class. Doing it at the HibernateTemplate level means the Interceptor will only be applied to any new Sessions that are created by the HibernateTemplate itself.

          Rob

          Comment

          Working...
          X