Announcement Announcement Module
Collapse
No announcement yet.
HibernateInterceptor vs. HibernateTxManger for an open session in BO Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HibernateInterceptor vs. HibernateTxManger for an open session in BO

    Greetings,

    We want a hibernate session to be opened in a business method to navigate through the object graph. Is it better to use HibernateTransactionManger to methods that need the session but performs no transactions ( most of our business methods just need to traverse object graph ) or to use HibernateInterceptor. From the documentation for HibernateInterceptor, we are not able to find a way to specify methods that need an open session. A session seems to be created for all business methods when using HibernateInterceptor.

    Here's our HibernateTransactionManager code..

    <bean id="aclHibernateTransactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory">
    <ref local="aclHibernateSessionFactory" />
    </property>
    </bean>

    <bean id="aclTxTemplate" abstract="true" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager">
    <ref bean="aclHibernateTransactionManager" />
    </property>
    </bean>

    <bean id="aclBO" parent="aclTxTemplate">
    <property name="target">
    <bean class="com.icrossing.aclocal.acl.model.impl.AclBO" >
    <property name="aclDAO">
    <ref bean="aclDAO" />
    </property>
    </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="getAclInfoForAllArea">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    And our HibernateInterceptor..

    <bean id="aclHibernateInterceptor" class="org.springframework.orm.hibernate3.Hibernat eInterceptor">
    <property name="sessionFactory">
    <ref bean="aclHibernateSessionFactory"/>
    </property>
    </bean>

    <bean id="aclBO" class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="target">
    <ref bean="aclBOTarget" />
    </property>
    <property name="proxyInterfaces">
    <value>com.icrossing.aclocal.acl.model.interfaces. IAclBO</value>
    </property>
    <property name="interceptorNames">
    <list>
    <value>aclHibernateInterceptor</value>
    </list>
    </property>
    </bean>

    Please let us know.

    Thanks,
    Bagath.
    Last edited by Bagath; Dec 16th, 2005, 05:16 PM.

  • #2
    I think you are confusing the purpose of the classes. HibernateTM drives the transactions while the Interceptor actually opens or injects a session into the thread for your class to use (through HibernateTemplate or HBCallback). In most cases you will use them together - the interceptor to inject and the TM to commit/rollback.
    To create sessions if one doesn't exist set the allowCreate to true (read the javadocs and especially the one from HibernateAccessor).

    Comment


    • #3
      Costin,

      Thanks for the reply.

      We got confused because in Professional Java Development with the Spring Framework, for lazy loading problem, they suggested using transactions and as per this document found in Karl Baum's Weblog http://www.jroller.com/page/kbaum/20040708 using HibernateInterceptor is suggested!

      We do not want to use transactions just to keep the session open in BO methods and we do not want to use Interceptor to all the methods in a BO.

      Thanks,
      Bagath.

      Comment

      Working...
      X