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 :

[Hibernate] Prb de conf ApplicationContext [Data]


Sujet :

Spring Java

  1. #1
    Membre confirmé
    Inscrit en
    Mars 2006
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 103
    Par défaut [Hibernate] Prb de conf ApplicationContext
    Bnjr,

    j éssaye de configurer ma premier APP Spring+hibernate mais j arrive pas avoir le prb j utilise spring 1.2.7 et hibernate 3
    voila mon fichier applicationContext:
    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
    67
    68
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
     
    <beans>	
    <!--                            HIBERNATE                               -->
    	<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<!-- Déclaration des fichiers de mapping -->
    		<property name="mappingResources">
    			<list>
    				<value>code/tables/Users.hbm.xml</value>
    			</list>
    		</property>		
    		<!-- Déclaration des paramètres liés à hibernate -->
    		<property name="hibernateProperties">
    			<props>
            <prop key="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</prop>
            <prop key="hibernate.connection.url">jdbc:mysql://localhost/profil1</prop>
            <prop key="hibernate.connection.username">root</prop>
            <prop key="hibernate.connection.password"></prop>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <!-- <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop> -->
            <prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
    				<!-- <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>  -->
    			</props>
    		</property>
    	</bean>
     
    	<!-- Gestionnaire des transactions Hibernate -->
    	<bean id="myTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory"><ref local="mySessionFactory"/></property>
    	</bean>
     
     
     
     
    	<bean id="myUserTransactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
    		<property name="transactionManager" ref="myTransactionManager"/>
    		<property name="transactionAttributeSource">
    			<value>code.service.IService.*=PROPAGATION_REQUIRED</value>
    		</property>
    	</bean>
     
     
    	<bean id="myHibernateUserService" class="code.dao.DaoImplDomaine">
    		<property name="sessionFactory"><ref local="mySessionFactory"/></property>		
    	</bean>
     
     
    	<bean id="mySpringUserServicesImpl" class="code.service.ServiceImpl">
    		<property name="serviceDAO" ref="myHibernateUserService"/>
    	</bean>
     
     
    	<bean id="myUserService" class="org.springframework.aop.framework.ProxyFactoryBean">
    		<property name="proxyInterfaces">
    			<value>code.service.IService</value>
    		</property>
    		<property name="interceptorNames">
    			<list>
    				<value>myUserTransactionInterceptor</value>
    				<value>mySpringUserServicesImpl</value>
    			</list>
    		</property>
    	</bean>
     
    </beans>
    voila l erreur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    ERROR [main] - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myHibernateUserService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: net/sf/hibernate/Session
    java.lang.NoClassDefFoundError: net/sf/hibernate/Session
    	at java.lang.Class.getDeclaredMethods0(Native Method)
    	at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    merci d avance

  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 : 57
    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
    Billets dans le blog
    2
    Par défaut
    il te manque le .jar hibernate3 dans le classpath

  3. #3
    Membre confirmé
    Inscrit en
    Mars 2006
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 103
    Par défaut
    ça marche .
    le jar y été dans LIB, j ai just modifier le nom de bean ne corespondé pas a celui utilisé dans la couche service
    merci pour ton aide

  4. #4
    Membre confirmé
    Inscrit en
    Mars 2006
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 103
    Par défaut session d' hibernate
    slt a tous,

    j ai essayé de regler un prb dans la couche DAO mais j y arrive pas

    l erreur
    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
    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.LocalSessionFactoryBean$TransactionAwareInvocationHandler.invoke(LocalSessionFactoryBean.java:1067)
    	at $Proxy0.getCurrentSession(Unknown Source)
    	at code.dao.DaoImplDomaine.exists(DaoImplDomaine.java:20)
    	at code.tests.TestDao.test1(TestDao.java:39)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at junit.framework.TestCase.runTest(TestCase.java:154)
    	at junit.framework.TestCase.runBare(TestCase.java:127)
    	at junit.framework.TestResult$1.protect(TestResult.java:106)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at junit.framework.TestResult.run(TestResult.java:109)
    	at junit.framework.TestCase.run(TestCase.java:118)
    	at junit.framework.TestSuite.runTest(TestSuite.java:208)
    	at junit.framework.TestSuite.run(TestSuite.java:203)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
    le code de ma couche DAO:
    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
    package code.dao;
     
    import code.dao.DaoException;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
     
    import code.tables.*;
     
    public class DaoImplDomaine implements IDao {
    	private SessionFactory sessionFactory;
     
     
    	public void setSessionFactory(SessionFactory sessionFactory) {
    		this.sessionFactory = sessionFactory;
    	}
     
    	public Users exists(String login, String password){
    		Session session = sessionFactory.getCurrentSession();
    		Users p2=null;
    		p2= (Users)session.createQuery("from Users where loginn = '" + login + "' and passwordd = '" + password + "'");
    		if(p2==null){
    			throw new DaoException("login inconnue", 2);
    		}
    	    return p2;
    	}
    }
    merci

  5. #5
    Rédacteur
    Avatar de lunatix
    Homme Profil pro
    Architecte technique
    Inscrit en
    Novembre 2002
    Messages
    1 960
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Architecte technique

    Informations forums :
    Inscription : Novembre 2002
    Messages : 1 960
    Par défaut
    remplace
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    sessionFactory.getCurrentSession();
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    sessionFactory.openSession();
    et ca va marcher. Ton problème est un peu complexe avec getCurrentSession (c'est lié a la gestion des transactions, ça vaut pas le coup de se prendre la tête tout de suite dessus)

  6. #6
    Membre confirmé
    Inscrit en
    Mars 2006
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 103
    Par défaut
    merci
    mais là j ai une autre erreur est ce que ma requette HQL est fausse??

    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
    java.lang.ClassCastException: org.hibernate.impl.QueryImpl
    	at code.dao.DaoImplDomaine.exists(DaoImplDomaine.java:20)
    	at code.tests.TestDao.test1(TestDao.java:39)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at junit.framework.TestCase.runTest(TestCase.java:154)
    	at junit.framework.TestCase.runBare(TestCase.java:127)
    	at junit.framework.TestResult$1.protect(TestResult.java:106)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at junit.framework.TestResult.run(TestResult.java:109)
    	at junit.framework.TestCase.run(TestCase.java:118)
    	at junit.framework.TestSuite.runTest(TestSuite.java:208)
    	at junit.framework.TestSuite.run(TestSuite.java:203)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)

  7. #7
    Rédacteur
    Avatar de lunatix
    Homme Profil pro
    Architecte technique
    Inscrit en
    Novembre 2002
    Messages
    1 960
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Architecte technique

    Informations forums :
    Inscription : Novembre 2002
    Messages : 1 960
    Par défaut
    non, mais dans
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    p2= (Users)session.createQuery("from Users where loginn = '" + login + "' and passwordd = '" + password + "'");
    ton cast n'est pas bon session.createQuery() renvoie query (pas Users), ensuite tu peux faire session.createQuery("...").list() pour avoir une java.util.List ou meme .uniqueResult() pour avoir Object (que la tu peux caster en Users)

  8. #8
    Membre confirmé
    Inscrit en
    Mars 2006
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 103
    Par défaut
    ok ça marche merci pour ton aide

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. prb de connexion de hibernate
    Par sonia5 dans le forum JSF
    Réponses: 9
    Dernier message: 02/09/2009, 16h38
  2. [Data] configuration applicationContext spring avec hibernate
    Par riderfun dans le forum Spring
    Réponses: 4
    Dernier message: 25/05/2009, 16h03
  3. [Utilisation d'Hibernate + probleme de conf]
    Par xarius dans le forum Hibernate
    Réponses: 3
    Dernier message: 05/06/2007, 12h10
  4. [HIBERNATE] Conf et classe not found
    Par djodjo dans le forum Hibernate
    Réponses: 2
    Dernier message: 10/05/2006, 17h37
  5. [Data] [STRUTS][HIBERNATE] fichier de conf
    Par nikalkal dans le forum Spring
    Réponses: 1
    Dernier message: 26/04/2006, 18h10

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