Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Multiple Hibernate Entity Interceptors?

  1. #11
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    rmangi,

    If I understand what you said, deciding what interceptor to use depends on the entity and method called.

    So lets configure our interceptors as plain POJOs
    Code:
      <bean id="interceptor1" class="Interceptor1"/> 
      <bean id="interceptor2" class="Interceptor2"/> 
      ...
    Now we create the uber-interceptor with a property of type map that holds the (entity, interceptor) pairs
    Code:
      <bean id="myInterceptor" class="MyInterceptor">
        <property name="interceptors">
          <entry key="entity1"> 
           <value>interceptor1</value>
          </entry> 
          <entry key="entity2"> 
           <value>interceptor2</value>
          </entry> 
        <property>
      </bean>
    myInterceptor will lookup the interceptor to be used for each call using the interceptors map:

    Code:
      public class MyInterceptor implements Interceptor, Serializable &#123;
    
        private map interceptors;
        //getters and setters
    
        ...
    
        public void onDelete&#40;Object entity,
                             Serializable id,
                             Object&#91;&#93; state,
                             String&#91;&#93; propertyNames,
                             Type&#91;&#93; types&#41; &#123;
            Interceptor interceptor = resolveInterceptor&#40;entity&#41;;
            if &#40;interceptor != null&#41;
              interceptor.onDelete&#40;entity, id, state, propertynames, types&#41;;
        &#125;
    
        ...
    
        //interceptor resolver
        private Interceptor resolveInterceptor&#40;Object entity&#41; &#123;
          //uses property interceptors, if not found returns null
          ...
          return interceptor;
        &#125;
      &#125;
    I did not try this solution before, but It seems extensible.
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  2. #12
    Join Date
    Aug 2004
    Location
    Brooklyn, NY
    Posts
    20

    Default

    Yes, that's pretty much where I'm headed right now. I'd like it to be smart enough to be aware of which methods a particular interceptor is overriding to avoid extra method calls (although they would be quick if they just return null). I'd also like it to be able to call two interceptors in the case where there may be more than 1 interceptor interested in a particular method call (not currently the case, but in the interest of the best possible solution...)

    None of this is rocket science, it just seems like a duplication of a lot of the functionality offered in other packages in spring, but not available for the hibernate entity interceptors. That's really my reason for asking about this.

    Thanks,

    Rick

  3. #13
    Join Date
    Aug 2004
    Location
    Brno, Czech Republic
    Posts
    48

  4. #14
    Join Date
    Aug 2004
    Location
    Brooklyn, NY
    Posts
    20

    Default

    Thanks. Good to see others have thought about this problem.

Similar Threads

  1. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  2. Multiple Data Sources + Hibernate + Spring
    By joeserel in forum Data
    Replies: 2
    Last Post: May 18th, 2005, 09:22 AM
  3. Other Hibernate DAO LazyInitializationExceptions
    By bernardsirius in forum Data
    Replies: 5
    Last Post: Feb 18th, 2005, 04:09 PM
  4. Replies: 9
    Last Post: Feb 8th, 2005, 09:25 PM
  5. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM

Posting Permissions

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