Results 1 to 6 of 6

Thread: Usage of Open Session in View in an OSGi environment

  1. #1
    Join Date
    Aug 2004
    Location
    France - Saint Nazaire
    Posts
    79

    Default Usage of Open Session in View in an OSGi environment

    Hello,

    I try to use the "Open Session in View" feature of Spring in an OSGi environment (I made some tries with the classes OpenSessionInViewFilter and OpenSessionInViewInterceptor for Hibernate3). It seems that the informations stored in the thread local are not shared between different bundles.

    Is there a special configuration in order to make it work with OSGi?

    Thanks for your help,
    Thierry

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

    Default

    I can't see a reason why the information is not shared between the thread locals - probably there are class visibility issues but otherwise, since the code is ran on the same VM, the thread locals should be all running inside the same space.
    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
    Aug 2004
    Location
    France - Saint Nazaire
    Posts
    79

    Default

    Hi Costin,

    Thanks for your answer!!

    I configure my session factory as a bean in my data access bundle and use it directly to configure my transaction manager bean:

    Code:
    <bean id="sessionFactory"
               class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
               lazy-init="false">
        (...)
        <property name="dataSource">
            <osgi:reference interface="javax.sql.DataSource" timeout="5000"/>
        </property>
    </bean>
    
    <osgi:service ref="sessionFactory" context-class-loader="service-provider">
        <osgi:interfaces>
            <value>org.hibernate.SessionFactory</value>
        </osgi:interfaces>
    </osgi:service>
    
    (...)
    
    <bean id="hibernateTransactionManager"
                class="org.springframework.orm.hibernate3.HibernateTransactionManager"
                lazy-init="false">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    On the other side, I configure my open session in view interceptor using the OSGi service related to the session factory in my web bundle:

    Code:
    <bean id="urlMapping"
                class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                (...)
            </props>
        </property>
        <property name="interceptors">
            <list>
                <ref local="openSessionInViewInterceptor"/>
            </list>
        </property>
    </bean>
        
    <bean id="openSessionInViewInterceptor"
               class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    
    <osgi:reference id="sessionFactory"
                               interface="org.hibernate.SessionFactory"
                               timeout="5000"/>
    Do you believe that Spring can make match the session factory because the first is the classic bean and the other the OSGi service?

    Thanks,
    Thierry

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

    Default

    What version of Spring are you using? The problem might arise from the fact that the transaction manager might use the session factory as a key which can fail when the session factory is used through the service registry.
    An alternative would be to externalize the session factory in its own bundle so everybody uses it through the service registry and thus there would no identity problems.
    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

  5. #5
    Join Date
    Aug 2004
    Location
    France - Saint Nazaire
    Posts
    79

    Default

    Hello Costin,

    I believe you're right. I will create a dedicated bundle for my business objects and my session factory.
    Thanks very much for your help!
    Thierry

  6. #6
    Join Date
    Jun 2007
    Posts
    6

    Default

    We too faced the same issue and we are not in position to externalize sessionFactory from the bundle.

    Hence we have exposed HibernateTransactionManager as OSGi service and get the session factory from the transaction manager. The object identity of session factory is same now.

    This post has given great clue for me to solve the issue. Thanks for the appropriate reply.

Posting Permissions

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