No Hibernate Session bound to thread, ejb3 stateless et Spring
Bonjour,
J'ai un soucis depuis cette après-midi avec une session Hibernate récalcitrante.
J'explique mon problème :
j'ai un ejb3 stateless déployé sur un serveur jBoss qui se voit injecter un dao via Spring.
Voici une partie de l'ejb :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
@Stateless(name="projetManager")
@Interceptors(SpringBeanAutowiringInterceptor.class)
@Transactional (propagation=Propagation.REQUIRED)
public class ProjetManagerBean implements ProjetManagerRemote, ProjetManagerLocal {
@Autowired
@Qualifier("projetDao")
private ProjetManagerDao projetDao;
public void addProjet(String param) {
projetDao.addProjet(param);
}
} |
Voici le Dao en question :
Code:
1 2 3 4 5 6 7 8 9 10 11
|
public class ProjetManagerDaoImpl extends HibernateTemplate implements ProjetManagerDao {
public void addProjet(String param) {
Projet p = new Projet(param);
getSessionFactory().getCurrentSession().persist(p);
}
} |
Voici la configuration Spring pour injecter le dao dans l'ejb :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
<bean id="projetDaoTransaction"
class="fr.lewolf.travelmate.service.dao.impl.ProjetManagerDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- sessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration
</value>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionProxy" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED, readOnly
</prop>
</props>
</property>
</bean>
<bean id="projetDao" parent="transactionProxy">
<property name="target">
<ref bean="projetDaoTransaction" />
</property>
<property name="transactionAttributeSource">
<bean
class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource" />
</property>
</bean> |
Tout me parait bien configuré seulement, lorsque j'invoque la méthode de l'ejb pour ajouter un projet, cette exception m'est retrounée :
Code:
1 2 3 4 5 6 7 8 9 10 11
|
Caused by: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:544)
at fr.lewolf.travelmate.service.dao.impl.ProjetManagerDaoImpl.addProjet(ProjetManagerDaoImpl.java:14)
at fr.lewolf.travelmate.service.metier.impl.ProjetManagerBean.methodeTest(ProjetManagerBean.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
.... |
Au début je pensais que le bean "sessionFactory" n'était pas injecté dans le dao mais lorsque je débug l'invocation, la sessionFactory est bien renseignée. Ce n'est que lorsque j'invoque la méthode "getSessionFactory().getCurrentSession()" que l'exception m'en retournée, sûrement par de l'aop d'ailleurs.
J'ai cherché de l'aide sur les forums mais toutes les solutions partielles que j'ai trouvées ne m'ont pas aidé à résoudre mon problème.
Connaîtriez-vous l'origine de ce problème et avez-vous une solution pour le résoudre ?
Je vous remercie d'avance.