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

Persistance des données Java Discussion :

L' Erreur java.lang.Assertion.Error


Sujet :

Persistance des données Java

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2009
    Messages : 22
    Points : 21
    Points
    21
    Par défaut L' Erreur java.lang.Assertion.Error
    Bonjour,
    j'ai une erreur dans mon code, je n'arrive pas à la trouver
    Voila mes fichiers:
    persistence.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
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.0"
    	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_2_0.xsd ">
    	<persistence-unit name="UP_BOUTIQUE" transaction-type="RESOURCE_LOCAL">
    		<provider>org.hibernate.ejb.hibernate.HibernatePersistence</provider>
    		<properties>
     
    			<property name="hibernate.show_sql" value="true" />
    			<property name="hibernate.hbm2dl.auto" value="create" ></property>
    			<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
     
    		</properties>
    	</persistence-unit>
    </persistence>
    et
    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
    <?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-3.2.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
     
    	<bean id="datasource"
    		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
    		<property name="url" value="jdbc:mysql://localhost:3306/eboutique"></property>
    		<property name="username" value="root"></property>
    		<property name="password" value=""></property>
    	</bean>
     
     
     
    	<bean id="persistenceUnitManager"
    		class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
    		<property name="defaultDataSource" ref="datasource"></property>
    		<property name="persistenceXmlLocations">
    			<list>
    				<value>classpath*:META-INF/persistence.xml</value>
    			</list>
    		</property>
    	</bean>
    	<bean id="entityManagerFactory"
    		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="persistenceUnitManager" ref="persistenceUnitManager"></property>
    		<property name="persistenceUnitName" value="UP_BOUTIQUE"></property>
    	</bean>
    	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory"></property>
    	</bean>
    	<tx:annotation-driven transaction-manager="transactionManager" />
    	<context:annotation-config></context:annotation-config>
     
     
     
     
     
     
    </beans>
    et mon test unitaire
    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
    package org.sid.eboutique;
     
    import static org.junit.Assert.*;
    import org.junit.Before;
    import org.junit.Test;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
     
     
     
     
    public class TesJPA {
    	@Before
    	public void setUp() throws Exception {
    	}
     
    	@Test
    	public void test1() {
    		try {
    			ClassPathXmlApplicationContext app=
    			new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"});
    			assertTrue(true);
    			} catch (Exception e) {
    			assertTrue(e.getMessage(),false);
    			}
    	}
     
    }
    et mon 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
    21
    22
    23
    24
    25
    26
    27
    java.lang.AssertionError: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Cannot find class [org.hibernate.ejb.hibernate.HibernatePersistence]
    	at org.junit.Assert.fail(Assert.java:91)
    	at org.junit.Assert.assertTrue(Assert.java:43)
    	at org.sid.eboutique.TesJPA.test1(TesJPA.java:23)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:483)
    	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

  2. #2
    Membre confirmé Avatar de freddou17
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2013
    Messages
    341
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2013
    Messages : 341
    Points : 566
    Points
    566
    Par défaut
    Slt comment lances tu ton tes TU par eclipse, avec maven? je pense que c'est un problème de classpath car tu as un CNP...

    ++

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2009
    Messages : 22
    Points : 21
    Points
    21
    Par défaut
    je ne comprends pas ta question?

  4. #4
    Membre confirmé Avatar de freddou17
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2013
    Messages
    341
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2013
    Messages : 341
    Points : 566
    Points
    566
    Par défaut
    Tes tests unitaires sont lancés comment? par maven=> mvn test:test par exemple ou tu fais Run as Junit test (ou équivalent si tu n'utilises pas éclipse).
    Pour moi ton problème est que tu n'as pas le bon classpath pour le scope Test

    c'est mieux?

    ++

  5. #5
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2009
    Messages : 22
    Points : 21
    Points
    21
    Par défaut
    oui je fais Run as JUnit Test pur lancer le test TesJPA

  6. #6
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2009
    Messages : 22
    Points : 21
    Points
    21
    Par défaut
    en console j'ai :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    INFO : org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@6ad5c04e: startup date [Fri Jan 16 09:49:38 CET 2015]; root of context hierarchy
    INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [applicationContext.xml]
    INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
    INFO : org.springframework.jdbc.datasource.DriverManagerDataSource - Loaded JDBC driver: com.mysql.jdbc.Driver
    INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@87f383f: defining beans [datasource,persistenceUnitManager,entityManagerFactory,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy

  7. #7
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2009
    Messages : 22
    Points : 21
    Points
    21
    Par défaut
    Je viens de trouver l'erreur
    elle se situe dans persistence.xml
    il y avait <provider>org.hibernate.ejb.hibernate.HibernatePersistence</provider>
    il faut le remplacer par le <provider>org.hibernate.ejb.HibernatePersistence</provider> il faut regarder dans les dépendances de Maeven
    Nom : maeven1.png
Affichages : 2987
Taille : 28,5 Ko

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

Discussions similaires

  1. Réponses: 0
    Dernier message: 27/04/2015, 23h10
  2. Erreur "java.lang.Error: Unresolved compilation problem:"
    Par sali-ft dans le forum Débuter avec Java
    Réponses: 2
    Dernier message: 01/05/2013, 15h57
  3. Réponses: 1
    Dernier message: 03/08/2010, 10h17
  4. Probleme erreur java.lang.NullPointerException
    Par Tsukaasa dans le forum Langage
    Réponses: 4
    Dernier message: 25/05/2006, 18h19
  5. Eclipse erreur : java.lang.OutOfMemoryError: Java heap space
    Par sderecourt dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 14/04/2006, 11h28

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