Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 11:49 Go to next message
Alexander Kosarev is currently offline Alexander KosarevFriend
Messages: 3
Registered: October 2012
Junior Member
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 06:46 Go to previous messageGo to next message
Thorsten Schlathölter is currently offline Thorsten SchlathölterFriend
Messages: 312
Registered: February 2012
Location: Düsseldorf
Senior Member
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 15:41 Go to previous messageGo to next message
Anatoly Osiko is currently offline Anatoly OsikoFriend
Messages: 1
Registered: October 2012
Junior Member
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 23:31 Go to previous message
Mastah Naleh is currently offline Mastah NalehFriend
Messages: 32
Registered: April 2012
Member
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 23:34]

Report message to a moderator

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


Current Time: Fri Apr 19 10:33:24 GMT 2024

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

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

Back to the top