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

JPA Java Discussion :

Fichier persistence.xml non reconnu


Sujet :

JPA Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2009
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2009
    Messages : 12
    Par défaut Fichier persistence.xml non reconnu
    Bonjour à tous : )

    Je vous expose un petit problème bien embêtant, à force de parcourir des tutoriel, etc et ne pas en trouvé de réponse.

    J'ai une application serveur Spring 3 - Ejb3 - Jpa - Hibernate - mysql - tomcat

    J'ai configuré le context de spring mais celui-ci me retourne une erreur, lors de la recherche de mon fichier de persistence.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    GRAVE: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in ServletContext resource [/WEB-INF/classes/webApplicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/classes/webApplicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No persistence unit with name 'jpaVille' found
    Voici mon context spring - Référence : bean "entityManager"

    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
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
     
    <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"
    	xmlns:context="http://www.springframework.org/schema/context" 
    	xmlns:jee="http://www.springframework.org/schema/jee"
    	xsi:schemaLocation="
           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
           http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
           <!-- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
           		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
    	        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd" -->
     
    	   <!-- ************ SERVICE *********** -->
     
    <!-- La Transaction -->
     
    	 <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory"/>
    	</bean>
    	<tx:advice id="serviceTxAdvice" transaction-manager="txManager">
    		<tx:attributes>
    			<tx:method name="find*" propagation="REQUIRED" read-only="true" />
    			<tx:method name="*" propagation="REQUIRED" />
    		</tx:attributes> 
    	</tx:advice>
        <aop:config>
    		<aop:pointcut id="serviceMethods" expression="execution(* service.nasch.*.*(..))" />
    		<aop:advisor advice-ref="serviceTxAdvice" pointcut-ref="serviceMethods" />
    	</aop:config>
     
     
    	<!-- Configuration de proxy spécifiques, héritant du proxy général, devant chaque bean potentiellement transactionnel -->
     
    	<!-- ***********************
    	      **    Beans Service   **
    	      ************************ --> 
     
    <bean id="ServiceContinentGeonamesTarget" class="service.nasch.ville.ServiceContinentGeonames">
    	<property name="continentDao" ref="continentDao"/>
    </bean>
     
    	<bean id="ServiceContinentGeonames" parent="transactionProxy">
    		<property name="target">
    			<ref bean="ServiceContinentGeonamesTarget"/>
    		</property>
    		<property name="transactionAttributeSource">
    			<bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>
    		</property>
    	</bean>
     
    	<!-- ************ MODELE ************** -->
     
    		  <!-- ***************************
    	      **    TransactionManager	    **
    	      ***************************** --> 
     
    	<!-- Gestions des Transactions BDD  -->
    	<!-- Définition du proxy général abstrait de manière globale à lapplication -->
    	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory"/>
    	</bean>
     
    		  <!-- ****************************
    	      **     TransactionProxy	    **
    	      ***************************** --> 
    	<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>
     
    	      <!-- ***********************
    	      **     BDD DataSource	    **
    	      ************************ --> 
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    	<property name="driverClassName">
    		<value>com.mysql.jdbc.Driver</value>
    	</property>
    	<property name="url">
    		<value>jdbc:mysql://localhost:3306/madb</value>
    	</property>
    	<property name="username">
    		<value>root</value>
    	</property>
    	<property name="password">
    		<value>mdp</value>
    	</property>
    </bean>
     
     
    <bean id="entityManagerFactory" 
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="persistenceUnitName" value="jpaVille"/>
        <property name="jpaVendorAdapter"> 
          <bean 
    		class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    		<property name="generateDdl" value="true" />
            <property name="showSql" value="true" />
            <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
    	</bean>
        </property> 
      </bean> 
     
     
    		  <!-- ***********************
    	      **    JBDC Exception	    **
    	      ************************ --> 
    <bean id="jdbcExceptionTranslator" class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator ">
    	<property name="dataSource">
    		<ref bean="dataSource"/>
    	</property>
    </bean>
     
     
    	 	  <!-- ***********************
    	      **    Beans DAO   **
    	      ************************ --> 
    	<!-- General  -->
    	<bean id="continentDao" class="dao.nasch.ville.impl.ContinentGeonamesHome">
    		<property name="entityManagerFactory">
    			<ref bean="entityManagerFactory"/>
    		</property>
    	</bean>
     
     
    	   <!-- *********** BEAN FOR TEST *************** -->
     
    	   <bean id="welcomeServiceBean" class="com.nasch.welcomeService.WelcomeService"/>
     
     
    	   <!-- *********** CLASS ************ -->
     
    	    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
     
       		<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
     
    	   <!-- *************  PACKAGE ******************* -->
    	   <!--  tell spring to use annotation based congfigurations -->
    		<context:annotation-config/>
    		<!--  tell spring where to find the beans -->
    		<context:component-scan base-package="dao.nasch.ville.impl" />
     
    		<tx:annotation-driven/>
     
    		<tx:jta-transaction-manager/>
     
     
    </beans>
    Mon fichier "persistence.xml" situé dans "META-INF"
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    <persistence xmlns="http://java.sun.com/xml/ns/persistence" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
      version="1.0"> 
     
      <persistence-unit name="jpaVille" transaction-type="JTA"> 
        <class>dao.nasch.ville.impl.ContinentGeonamesHome</class> 
      </persistence-unit> 
     
    </persistence>
    la classe ContinentGeonames (pour donner une idée), car là je n'intitule le nom de référence de la persistence "jpaVille" en parametre de mon context "EntityManager" vu que je veux qu'il soit fait par Spring (je trouve que c'est mieux comme ça)

    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
     
    public class ContinentGeonamesHome {
     
    	private static final Log log = LogFactory
    			.getLog(ContinentGeonamesHome.class);
     
    /* PAS comme ça => @PersistenceContext(unitName="jpaVille")
      private EntityManager em; */
     
     
    	@PersistenceContext
    	private EntityManager entityManager;
     
    	public void persist(ContinentGeonames transientInstance) {
    		log.debug("persisting ContinentGeonames instance");
    		try {
    			entityManager.persist(transientInstance);
    			log.debug("persist successful");
    		} catch (RuntimeException re) {
    			log.error("persist failed", re);
    			throw re;
    		}
    	}
    Je ne vois pas pourquoi il n'est donc trouvé !!
    Entre des pb de classpath vu ailleurs (ayant donc ajouté caché au java build path le dossier "Meta-Inf")
    ou alors ajouté un jdni (mui bon, pas trop compris cette méthode, ça devrait marcher comme ça normalement),
    renommer le fichier (étrange, je pensais que c'était normalisé),
    ou même donner le nom du fichier et non celui de "persistence_unit".

    Mon classe path :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    <?xml version="1.0" encoding="UTF-8"?>
    <classpath>
    	<classpathentry kind="src" path="src"/>
    	<classpathentry kind="src" path="WebContent/META-INF"/>
    	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_14"/>
    	<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v6.0"/>
    	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
    .....
    .....
    <classpathentry kind="output" path="WebContent/WEB-INF/classes"/>
    </classpath>
    Je ne vois pas comment y résoudre.

    ps : si j'utilise la version :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    @PersistenceContext(unitName="jpaVille")
    	private EntityManager entityManager;
    j'ai une erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in ServletContext resource [/WEB-INF/classes/webApplicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/classes/webApplicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: No persistence units parsed from {classpath*:META-INF/persistence.xml}

  2. #2
    Membre confirmé
    Inscrit en
    Juin 2008
    Messages
    125
    Détails du profil
    Informations forums :
    Inscription : Juin 2008
    Messages : 125
    Par défaut
    Bonjour,

    Je rencontre le même problème. Aucune idée ?

    Merci.

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2009
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2009
    Messages : 12
    Par défaut
    Il y a une autre méthode qui fonctionne, du moins il n'y a plus cette erreur ou il ne trouve pas notre"persistence-unit-name".

    Tu spécifie un "persistenceUnitManager" au lieu d'un "persistenceUnitName"
    Et tu décrit ton bean "persistenceUnitManager"

    Un exemple associé à ce que j'ai fait :

    Dans ton fichier context.xml de spring :

    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
     
    <!-- JPA PersistenceUnitManager used to customize the selection of the persistence unit and the datasources -->
    	<bean id="persistenceUnitManager"
    		class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
    		<!-- Multiple value can be specified here -->
    		<property name="persistenceXmlLocations">
    			<list>
    				<value>classpath*:./persistence.xml</value>
    			</list>
    		</property>
    		<property name="dataSources">
    			<map>
    				<entry key="localDataSource" value-ref="dataSource" />
    				<!--<entry key="remoteDataSource" value-ref="remote-db" />-->
    			</map>
    		</property>
    		<!-- if no datasource is specified, use this one -->
    		<property name="defaultDataSource" ref="dataSource" />
    	</bean>
     
    <bean id="entityManagerFactory" 
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="persistenceUnitManager" ref="persistenceUnitManager"/>
        <property name="jpaVendorAdapter"> 
          <bean 
    		class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    		<property name="generateDdl" value="true" />
            <property name="showSql" value="true" />
            <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
    	</bean>
        </property> 
      </bean>
    Note : il te faudra peut être changer le chemin de ton classpath.
    (mais je vais essayer de changer ça, celui par origine est plus correct je pense).

    Un tuto ici http://spring.developpez.com/faq/?page=database

    ça ne résous qu'a moitié le problème.

    Premièrement dans ce tuto, la conception de cet "persistenceUnitManager" n'est pas obligatoire, dans ce cas je me demande bien comment l'ont peut faire référence à notre persistence !!!!!

    Deuxièmement : J'ai crée une console hibernate, indiquant dans le fichier de configuration associé le nom de ma persistence , ici "jpaVille", et cela plante car il n'est pas trouvé.

    Pourtant il apparait bien dans mon "WEB-INF\classes"

    Mais je pense savoir pourquoi, car il doit être dans le dossier "classes\META-INF" et non "classes" je suppose !! encore creuser...
    Je n'ai pas de dossier META-INF dans le dossier "classes" c'est embêtant

    quel est ton classPath ?

Discussions similaires

  1. Réponses: 11
    Dernier message: 29/07/2009, 10h31
  2. Réponses: 0
    Dernier message: 22/07/2009, 16h31
  3. Fichier hbm.xml non trouvé
    Par joseph_p dans le forum Hibernate
    Réponses: 2
    Dernier message: 26/05/2006, 10h58
  4. Réponses: 3
    Dernier message: 12/10/2005, 13h53
  5. fichier global.asa non reconnu
    Par zorba49 dans le forum ASP
    Réponses: 6
    Dernier message: 26/08/2005, 11h04

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