These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Pb Initialisation de Session avec Spring & HibernateTemp
PostPosted: Fri Jan 12, 2007 9:35 am 
Newbie

Joined: Fri Jan 12, 2007 9:24 am
Posts: 1
Bonjour à tous ,

je cherche à utiliser Spring avec Hibernate3. Dans le fichier de définition de spring j'ai défini une SessionFactory et l'ai injectée dans mon DAO qui hérite de HibernateDAOSupport.
Cependant lorsque je tente d'exécuter l'une ou l'autre des méthodes ci dessous une erreur org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed. est remontée.

Code :

public class monDAOImpl extends HibernateDaoSupport
{
public monBeanHibernate findByPrimaryKey1(String symbolicName) {
return (monBeanHibernate) getHibernateTemplate().load(monBeanHibernate.class, symbolicName);
}

public monBeanHibernate findByPrimaryKey2(String symbolicName) {
return (monBeanHibernate) getSession().load(monBeanHibernate.class, symbolicName); }
}

Pourtant si je tente une ouverture de session avec un getSessionFactory().openSession() et que j'exécute tout se passe bien. Je joins une partie de la configuration spring. Visiblement le problème ne vient ni de la dataSource ni de la sessionFactory. Faut-il définir une factory method pour le DAO qui viendrait initialiser tout ca ? Je compte par le suite travailler avec la currentSession ou le hibernateTemplate mais s'ils sont mal intialisés....

Code :

[...] // Définition DataSource, SessionFactory
<aop:config>
<aop:pointcut id="methodesDAO" expression="execution(* org.monpackage.monDAOImpl.*(..))" />
<aop:advisor advice-ref="transactionRegles" pointcut-ref="methodesDAO">
</aop:config>

<tx:advice id="transactionRegles" transaction-manager="monManager">
<tx:attributes>
<tx:method name="get" read-only="true">
<tx:method name="*">
</tx:attributes>
</tx:advice>

<bean id="monManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="maSessionFactory" />
</bean>

<!-- Bean heritant de Hibernate DAO Support -->
<bean id="monDAO" class="org.monpackage.monDAOImpl" >
<property name="sessionFactory" ref="maSessionFactory" />
</bean>

J'ai dû manquer quelquechose. Quelqu'un aurait-il une idée je sens que c'est tout bête. J'ai suivi le tutoriel spring
http://www.springframework.org/docs/reference/orm.html chapitre 12 mais aussi 9)

J'ai cru comprendre que le HibernateTemplate gérait ses sessions lui même pas besoin de réaliser explicitement l'ouverture de session? Ou pourrais trouver un exemple ? Une gestion du transaction manager via AOP défaillante (genre mauvais expression de pointcut) pourrait elle expliquer le problème ?

Merci de toute réponse.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.