Announcement Announcement Module
Collapse
No announcement yet.
Circular dependencies Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Circular dependencies

    I'm having a little problem with a circular dependency issue. I would love to solve this through better software, but I am relying on Hibernate which I believe will make that impossible. Here is the situation:

    I have a standard Hibernate SessionContext. I have an Interceptor that I need to register with that context. That interceptor needs to know about the SessionContext, but it has to be registered with the context. Is there a way to lazy-initialize the interceptor without turning it into a singleton? Here is the Spring code:

    <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource"><ref local="cmDataSource"/></property>
    <property name="mappingResources">
    <list>
    <value>ListingDealer.hbm.xml</value>
    <value>AREA.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.Orac le9Dialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>
    <property name="entityInterceptor">
    <!-- THE HIBERNATE INTERCEPTOR -->
    <bean id="xmlBeansHibernateInterceptor" class="com.autotrader.spl.dao.XmlBeansHibernateInt erceptor">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>
    </property>
    </bean>
    </property>
    </bean>

    Thanks for your help.

    Brian Ashburn
    Senior Software Engineer
    AutoTrader.com

  • #2
    Originally posted by bashburn View Post
    I'm having a little problem with a circular dependency issue. I would love to solve this through better software, but I am relying on Hibernate which I believe will make that impossible. Here is the situation:

    I have a standard Hibernate SessionContext. I have an Interceptor that I need to register with that context. That interceptor needs to know about the SessionContext, but it has to be registered with the context. Is there a way to lazy-initialize the interceptor without turning it into a singleton? Here is the Spring code:

    Code:
    <!-- Hibernate SessionFactory -->
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource"><ref local="cmDataSource"/></property>
            <property name="mappingResources">
                <list>
                    <value>ListingDealer.hbm.xml</value>				
                    <value>AREA.hbm.xml</value>
                </list>
            </property>
            <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
            </property>
    		<property name="entityInterceptor">	
                <!-- THE HIBERNATE INTERCEPTOR -->
                <bean id="xmlBeansHibernateInterceptor" class="com.autotrader.spl.dao.XmlBeansHibernateInterceptor">
                    <property name="sessionFactory">
                        <ref bean="sessionFactory"/>
                    </property>
                </bean>
             </property>
        </bean>
    Thanks for your help.

    Brian Ashburn
    Senior Software Engineer
    AutoTrader.com


    Hi Brian,

    i also encounter this problem that time,

    this my workaround
    Code:
                <bean id="xmlBeansHibernateInterceptor" class="com.autotrader.spl.dao.XmlBeansHibernateInterceptor">
                    <property name="sessionFactory" value="sessionFactory" />
                </bean>
    in my XmlBeansHibernateInterceptor if will lookup the sessionFactory from Spring beanFactory.

    Comment

    Working...
    X