title: Hibernate 4 SessionFactory-scoped interceptor
body: <p>My Java applications uses Hibernate with a SessionFactory-scoped interceptor in order to change data before storing in the database.</p>
  
  <pre><code>myConfiguration.setInterceptor(new MyInterceptor());
  SessionFactory sf = myConfiguration.buildSessionFactory();
  </code></pre>
  
  <p>With the release 4.0 of hibernate they changed the concept of using the class Configuration.</p>
  
  <p>So my new approach is:</p>
  
  <pre><code>final ServiceRegistryBuilder srb = new ServiceRegistryBuilder();
  srb.configure(...);                // Hibernate configuration
  final ServiceRegistry sr = srb.buildServiceRegistry();
  final MetadataSources mds = new MetadataSources(sr);
  mds.add...();                      // All the meta data configurations
  final Metadata md = mds.buildMetadata();
  SessionFactory sf = md.buildSessionFactory();
  </code></pre>
  
  <p><strong>I have not found a point where to set the interceptor with this new approach.
  Any recommendations on how to set a SessionFactory-scoped interceptor?</strong></p>