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

Hibernate Java Discussion :

[Hibernate 4.0.1] org.hibernate.SessionFactory.getCurrentSession()Lorg/hibernate/classic/Session


Sujet :

Hibernate Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Mars 2012
    Messages
    165
    Détails du profil
    Informations forums :
    Inscription : Mars 2012
    Messages : 165
    Par défaut [Hibernate 4.0.1] org.hibernate.SessionFactory.getCurrentSession()Lorg/hibernate/classic/Session
    Bonjour,

    Je travaille sur un projet Maven dont j utilise Hibernate 4.0.1, Spring 3.1.1 et JSF 2.1.6.

    J'ai un problème au niveau de SessionFactory.

    Voilà la structure de mon application :



    Voilà mon fichier 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
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
     
    <!-- Beans Declaration -->
    	 <bean id="User" class="com.afkir.model.User"/>
     
    	 <!-- User Service Declaration -->
    	 <bean id="UserService" class="com.afkir.service.UserService">
    	  <property name="userDAO" ref="UserDAO" />
    	 </bean>
     
    	 <!-- User DAO Declaration -->
    	 <bean id="UserDAO" class="com.afkir.dao.UserDAO">
    	  <property name="sessionFactory" ref="SessionFactory" />
    	 </bean>
     
    	 <!-- Data Source Declaration -->
    	 <bean id="DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    	  <property name="driverClass" value="com.mysql.jdbc.Driver" />
    	  <property name="jdbcUrl" value="jdbc:mysql://localhost/DB_User" />
    	  <property name="user" value="root" />
    	  <property name="password" value="" />
    	  <property name="maxPoolSize" value="10" />
    	  <property name="maxStatements" value="0" />
    	  <property name="minPoolSize" value="5" />
    	 </bean>
     
    	 <!-- Session Factory Declaration -->
    	 <bean id="SessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    	  <property name="dataSource" ref="DataSource" />
    	  <property name="annotatedClasses">
    	   <list>
    	    <value>com.afkir.model.User</value>
    	   </list>
    	  </property>
    	  <property name="hibernateProperties">
    	   <props>
    	    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    	    <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop> 
    	   </props>
    	  </property>
    	 </bean>
     
    	 <!-- Enable the configuration of transactional behavior based on annotations -->
    	    <tx:annotation-driven transaction-manager="txManager" />
     
     
    	 <!-- Transaction Manager is defined -->
    	    <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    	       <property name="sessionFactory" ref="SessionFactory"/>
    	    </bean>
     
    	    <context:component-scan base-package="com.afkir"/>
    </beans>
    Mon fichier faces-config.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
    <?xml version="1.0" encoding="UTF-8"?>
     
    <faces-config
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
        version="2.0">
     
        <application>
    	     <el-resolver>
    	      org.springframework.web.jsf.el.SpringBeanFacesELResolver
    	     </el-resolver>
    	   </application>
     
    	 <!-- configuration of navigation rules -->
    	 <navigation-rule>
    	     <from-view-id>/pages/index.xhtml</from-view-id>
    	     <navigation-case>
    	         <from-outcome>success</from-outcome>
    	            <to-view-id>/pages/success.xhtml</to-view-id>
    	        </navigation-case>
    	         <navigation-case>
    	         <from-outcome>error</from-outcome>
    	            <to-view-id>/pages/error.xhtml</to-view-id>
    	        </navigation-case>
    	    </navigation-rule>
     
    </faces-config>
    Voilà mon fichier web.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
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>HibernateSpringJSF</display-name>
     
      <!-- Spring Context Configuration' s Path definition -->
          <context-param>
          		<param-name>contextConfigLocation</param-name>
          		<param-value>/WEB-INF/applicationContext.xml
          		</param-value>
    	  </context-param>
     
    	   <!-- The Bootstrap listener to start up and shut down Spring's root WebApplicationContext. It is registered to Servlet Container -->
    	   <listener>
    	   		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	   </listener>
    	   <listener>
    	   		<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    	   </listener>
     
    	   <!-- Project Stage Level -->
    	   <context-param>
    	     <param-name>javax.faces.PROJECT_STAGE</param-name>
    	     <param-value>Development</param-value>
    	   </context-param>
     
    	   <!-- Welcome Page -->
    	   <welcome-file-list>
    	     <welcome-file>/pages/index.xhtml</welcome-file>
    	   </welcome-file-list>
     
    	   <!-- JSF Servlet is defined to container -->
    	   <servlet>
    	     <servlet-name>Faces Servlet</servlet-name>
    	     <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    	     <load-on-startup>1</load-on-startup>
    	   </servlet>
     
    	   <!-- Mapping with servlet and url for the http requests. -->
    	   <servlet-mapping>
    	     <servlet-name>Faces Servlet</servlet-name>
    	     <url-pattern>*.jsf</url-pattern>
    	   </servlet-mapping>
    	   <servlet-mapping>
    	     <servlet-name>Faces Servlet</servlet-name>
    	     <url-pattern>*.faces</url-pattern>
    	   </servlet-mapping>
    	   <servlet-mapping>
        	 <servlet-name>Faces Servlet</servlet-name>
        	 <url-pattern>*.xhtml</url-pattern>
     	   </servlet-mapping>
     
    </web-app>
    Voilà ma page "index.xhtml" qui contient un formulaire et un bouton pour ajouter un utilisateur :

    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
    <html xmlns="http://www.w3.org/1999/xhtml"
    	     xmlns:h="http://java.sun.com/jsf/html"
    	      xmlns:f="http://java.sun.com/jsf/core"
    	     xmlns:p="http://primefaces.org/ui">
    	 <h:head><title>Welcome to OTV_JSF_Spring_Hibernate_Project</title></h:head>
    	 <h:body>
    	     <h:form>
    	      <table>
    	       <tr>
    	        <td><h:outputLabel for="id" value="Id : " /></td>
    	        <td><p:inputText id="id" value="#{userMB.id}">
    	          <f:converter converterId="javax.faces.Integer"/>
    	             <p:ajax event="blur" update="idMsg" />
    	         </p:inputText>
    	         <p:message id="idMsg" for="id" display="icon"/>
    	        </td>
    	       </tr>
    	       <tr>
    	        <td><h:outputLabel for="name" value="Name : " /></td>
    	        <td><p:inputText id="name" value="#{userMB.name}">
    	          <f:validateLength minimum="5" />
    	          <p:ajax event="blur" update="nameMsg" />
    	         </p:inputText>
    	         <p:message id="nameMsg" for="name" display="icon"/>
    	        </td>
    	       </tr>
    	       <tr>
    	        <td><h:outputLabel for="surname" value="Surname : " /></td>
    	        <td><p:inputText id="surname" value="#{userMB.surname}">
    	          <f:validateLength minimum="5" />
    	          <p:ajax event="blur" update="surnameMsg" />
    	         </p:inputText>
    	         <p:message id="surnameMsg" for="surname" display="icon"/>
    	        </td>
    	       </tr>
    	          <tr>
    	        <td><p:commandButton id="addUser" value="Add" action="#{userMB.addUser}" ajax="false"/></td>
    	        <td><p:commandButton id="reset" value="Reset" action="#{userMB.reset}" ajax="false"/></td>
    	       </tr>
    	      </table>
    	     </h:form>
    	</h:body>
    	</html>
    Quand je clique sur Ajouter, les erreurs ci-dessous s'affichent :

    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
    javax.faces.el.EvaluationException: java.lang.NoSuchMethodError: org.hibernate.SessionFactory.getCurrentSession()Lorg/hibernate/classic/Session;
    	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
    	at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    	at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    	at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    	at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    	at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.NoSuchMethodError: org.hibernate.SessionFactory.getCurrentSession()Lorg/hibernate/classic/Session;
    	at com.afkir.dao.UserDAO.addUser(UserDAO.java:31)
    	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 org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    	at $Proxy13.addUser(Unknown Source)
    	at com.afkir.service.UserService.addUser(UserService.java:26)
    	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 org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    	at $Proxy14.addUser(Unknown Source)
    	at com.afkir.managed.bean.UserManagedBean.addUser(UserManagedBean.java:41)
    	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 org.apache.el.parser.AstValue.invoke(AstValue.java:191)
    	at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
    	at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
    	... 20 more
    J'ai besoin de vos renseignements.

    Merci d'avance pour votre aide.
    Images attachées Images attachées  

  2. #2
    Membre émérite Avatar de slim
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2002
    Messages
    938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2002
    Messages : 938
    Par défaut
    Bonjour,

    C'est du côté du pom.xml qu'il faut chercher. Ce sont tes dépendances qu'il faut revoir, je pense. D'ailleurs, il y a une croix rouge sur ton projet.

    La stack te dit qu'il n'arrive pas à trouver la méthode getCurrentSession(). Tu dois utiliser plusieurs version d'hibernate.

    Autre chose, laisse tomber le sessionFactory et utilise un entityManagerFactory avec un data source.
    Pour tes Dao (Repos) utilise Spring Data. C'est beaucoup plus simple.
    Je te laisse chercher de la doc dessus...
    Faites une recherche sur le forum et/ou sur internet et lisez la doc officielle avant de poser une question svp.
    et n'oubliez pas de lire les FAQ !
    FAQ Java et les cours et tutoriels Java
    Doc JAVA officielle
    AngularJS 1.x
    Angular 2

    Do it simple... and RTFM !

Discussions similaires

  1. Réponses: 1
    Dernier message: 19/07/2013, 10h30
  2. Réponses: 1
    Dernier message: 16/05/2013, 19h40
  3. [Framework] Problème sessionFactory.getCurrentSession Spring
    Par aminedeveloppement dans le forum Spring
    Réponses: 11
    Dernier message: 19/04/2013, 17h13
  4. Réponses: 8
    Dernier message: 17/04/2008, 17h29
  5. [Hibernate] probleme de SessionFactory
    Par Elmilouse dans le forum Hibernate
    Réponses: 2
    Dernier message: 11/04/2006, 16h52

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