Results 1 to 3 of 3

Thread: HibernateInterceptor vs. HibernateTxManger for an open session in BO

  1. #1
    Join Date
    Dec 2005
    Posts
    4

    Default 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 at 04:16 PM.

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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).
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3
    Join Date
    Dec 2005
    Posts
    4

    Default

    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.

Posting Permissions

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