|Hibernate SessionFactory as osgi:service [message #954965]
||Tue, 23 October 2012 11:49
| Alexander Kosarev
Registered: October 2012
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 class="org.springframework.orm.hibernate4.HibernateTransactionManager" id="transactionManager"
<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
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
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 #960948 is a reply to message #954965]
||Sat, 27 October 2012 23:31
| Mastah Naleh
Registered: April 2012
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
Powered by FUDForum
. Page generated in 0.01859 seconds