Skip to main content



      Home
Home » Eclipse Projects » Virgo » Hibernate SessionFactory as osgi:service(I have some problems with it...)
Hibernate SessionFactory as osgi:service [message #954965] Tue, 23 October 2012 07:49 Go to next message
Eclipse UserFriend
Hi all! I develop a project containing 2 bundles. In first bundle I described session factory and transaction manager and publish them as osgi services:
<bean class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" id="sessionFactory">
	<property name="dataSource" ref="dataSource"/>
	...
</bean>

<bean class="org.springframework.orm.hibernate4.HibernateTransactionManager" id="transactionManager"
          p:sessionFactory-ref="sessionFactory"/>
          
<osgi:service id="sessionFactoryService" ref="sessionFactory" interface="org.hibernate.SessionFactory"/>

<osgi:service id="transactionManagerService" ref="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager"/>


In second bundle I described references to these services:
<osgi:reference id="sessionFactory" bean-name="sessionFactory" interface="org.hibernate.SessionFactory"/>
    
<osgi:reference id="transactionManager" bean-name="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager"/>


Contexts of both bundles have
<tx:annotation-driven transaction-manager="transactionManager"/>


I don't have any problems if I try to open new session and to use it. But if I try to get current session in second bundle (in first bundle it works fine), I get an error message:
Caused by: org.hibernate.HibernateException: No Session found for current thread
	at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
...


Is it real to work with session opened in another bundle?

Spring Framework version is 3.1.2, Hibernate - 4.1.7
Re: Hibernate SessionFactory as osgi:service [message #957346 is a reply to message #954965] Thu, 25 October 2012 02:46 Go to previous messageGo to next message
Eclipse UserFriend
Hi Alexander,
just to let you know: I have the same versions running with several bundles. Although I am not using annotation driven transactions, in general it should work.

Regards,
Thorsten
Re: Hibernate SessionFactory as osgi:service [message #960555 is a reply to message #957346] Sat, 27 October 2012 11:41 Go to previous messageGo to next message
Eclipse UserFriend
Sorry, I am not giving your an advise, vice versa, asking for one.

What configuration file contains the following directive - OSGI/blueprint.xml, or else?

<tx:annotation-driven transaction-manager="transactionManager"/>

I am trying adapt my Spring declarative transaction support experience to OSGi based application. But I have to add that my blueprint container is from Apache aries.
Re: Hibernate SessionFactory as osgi:service [message #960948 is a reply to message #954965] Sat, 27 October 2012 19:31 Go to previous message
Eclipse UserFriend
From memory no AOP is done on proxy of services made by blueprint because spring can't see the annotation.

Though, you can export DAO class as services since the spring magic is already done.

And in OSGi you export final service implemented from interface (API). I think it's a bad design to expose hibernate session as a service, but I could be wrong.


API (define service)
Consumer (import API, consume provider service)
Provider (import API, export service )

[Updated on: Sat, 27 October 2012 19:34] by Moderator

Previous Topic:How can I use JPA 2.0 with hibernate under virgo
Next Topic:Completeness of scoped plans
Goto Forum:
  


Current Time: Wed Jul 23 07:49:45 EDT 2025

Powered by FUDForum. Page generated in 0.27123 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top