Results 1 to 5 of 5

Thread: net.sf.hibernate.Interceptor and HibernateDaoSupport

  1. #1
    Join Date
    Dec 2004
    Posts
    9

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    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

  3. #3
    Join Date
    Dec 2004
    Posts
    9

    Default amazing!

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

  4. #4
    Join Date
    Dec 2004
    Posts
    9

    Default 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

  5. #5
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •