IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

Spring IOC + hibernate


Sujet :

Spring Java

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Février 2007
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Février 2007
    Messages : 30
    Points : 20
    Points
    20
    Par défaut Spring IOC + hibernate
    bonjour

    J'expérimente un petit problème de configuration de Spring et j'aimeriez que vous m'aidiez si possible...

    J'ai cru comprendre que pour bien faire les choses dans une application, on peut injecter les sessionFactory d'hibernate à l'aide de Spring IOC (dites-moi si je me trompe)

    J'ai donc fait ceci et celà semble avoir correctement été fait puisque j'ai alors obtenu le message d'erreur :

    org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

    En parcourant le net, j'ai alors cru comprendre qu'il faudrait fournir un "transactional scope". Est-ce exact ? Que dois-je faire sachant que je ne désire pas utiliser les fonctionnalités de persistance de Spring ?

    merci

    Mon ApplicationContext.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    <?xml version="1.0" encoding="UTF-8"?>
     
    <!-- <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> -->
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="
           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
     
     
     
    	<!-- Datasource that works in any application server
    	You could easily use J2EE data source instead if this were
    	running inside of a J2EE container.
    	-->
    	<bean id="dataSource" class="org.apache.tomcat.dbcp.dbcp.BasicDataSource" destroy-method="close">
    		<property name="driverClassName">
    			<value>com.mysql.jdbc.Driver</value>
    		</property>
    		<property name="url">
    			<value>jdbc:mysql://localhost/maDB</value>
    		</property>
    		<property name="username">
    			<value>root</value>
    		</property>
    		<property name="password">
    			<value>test</value>
    		</property>
    	</bean>
     
    	<!-- Hibernate SessionFactory -->
    	<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="configLocation">
    			<value>classpath:hibernate.cfg.xml</value>
    		</property>
    	</bean>
     
    	 <bean id="paysDao" class="com.company.paysApp.dao.impl.PaysDaoImpl">
     		<property name="sessionFactory">
     			<ref local="mySessionFactory"/>
     		</property>
     	</bean>
     
    	<!-- COMMENTAIRES
    		<tx:advice id="txAdvice" transaction-manager="txManager">
    			<tx:attributes>
    				<tx:method name="get*" read-only="true"/>
    				<tx:method name="*"/>
    			</tx:attributes>
    		</tx:advice>
     
    		<aop:config>
    			<aop:pointcut id="paysDaoOperation" expression="execution(* com.company.paysApp.dao..*.*(..))"/> 
    			<aop:advisor advice-ref="txAdvice" pointcut-ref="paysDaoOperation"/>
    		</aop:config>
     
     
    		<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    			<property name="dataSource" ref="dataSource"/>
    			<property name="sessionFactory" ref="mySessionFactory"/>
    		</bean>
    	 -->
    </beans>

  2. #2
    ego
    ego est déconnecté
    Rédacteur

    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Juillet 2004
    Messages
    1 883
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Architecte de système d'information
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 883
    Points : 3 510
    Points
    3 510
    Billets dans le blog
    2
    Par défaut
    il te faut définir un contexte transactionnel/session pour que tes appels Hibernate fonctionnent.
    Pour cela, il y a plusieurs méthodes dont entre autres utiliser un intercepteur côté Web qui va créer automatiquement une session Hibernate ou déclarer des services transactionnels, comme le permet Spring dans le fichier de configuration.
    Regardes la doc Spring sur le sujet, c'est assez explicite je crois.

Discussions similaires

  1. PrimeFaces, Spring IOC et Hibernate
    Par Neo01 dans le forum JSF
    Réponses: 5
    Dernier message: 21/08/2013, 19h42
  2. [Framework] Problem Spring IOC annotation hibernate
    Par walidjaha dans le forum Spring
    Réponses: 0
    Dernier message: 12/08/2011, 10h37
  3. Réponses: 5
    Dernier message: 12/05/2006, 22h02
  4. SPRING+STRUTS+HIBERNATE. Une bonne solution ?
    Par ollivier dans le forum Struts 1
    Réponses: 9
    Dernier message: 10/04/2006, 13h16
  5. [Hibernate][Spring] Session Hibernate initialisée
    Par mauvais_karma dans le forum Hibernate
    Réponses: 12
    Dernier message: 08/08/2005, 13h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo