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 :

[tests maven] AssertionError Héritage de classes


Sujet :

Hibernate Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Avatar de natoine
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Décembre 2007
    Messages
    393
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Chercheur en informatique

    Informations forums :
    Inscription : Décembre 2007
    Messages : 393
    Par défaut [tests maven] AssertionError Héritage de classes
    Donc j'ai une classe Document abstraite et une classe héritant de Document, DocumentHTML qui elle n'est pas abstraite.
    J'aimerai faire persister toutes mes instances de Document dans une même table.

    Je fais des tests unitaires dans mon projet Maven, mais je ne passe pas un test simple d'insertion d'un document.
    Je ne comprends pas l'erreur que me renvoie maven.

    Erreur :
    -------------------------------------------------------------------------------
    Test set: fr.natoine.annotations_persistence.document.DocumentTest
    -------------------------------------------------------------------------------
    Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.778 sec <<< FAILURE!
    testInsertDocument(fr.natoine.annotations_persistence.document.DocumentTest) Time elapsed: 0.767 sec <<< FAILURE!
    java.lang.AssertionError
    at org.hibernate.cfg.AnnotationBinder.getElementsToProcess(AnnotationBinder.java:817)
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:667)
    at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:546)
    at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:291)
    at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1162)
    at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1226)
    at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:191)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:253)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:125)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
    at fr.natoine.annotations_persistence.document.DocumentTest.testInsertDocument(DocumentTest.java:30)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at junit.framework.TestCase.runTest(TestCase.java:164)
    at junit.framework.TestCase.runBare(TestCase.java:130)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:120)
    at junit.framework.TestSuite.runTest(TestSuite.java:228)
    at junit.framework.TestSuite.run(TestSuite.java:223)
    at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
    at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:338)
    at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997)
    Code de Document :
    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
    package fr.natoine.annotations_persistence.document;
     
    import java.io.Serializable;
    import java.util.Date;
     
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.Inheritance;
    import javax.persistence.InheritanceType;
    import javax.persistence.MappedSuperclass;
    import javax.persistence.Table;
    import javax.xml.bind.annotation.XmlRootElement;
     
    @XmlRootElement
    @Entity
    @MappedSuperclass
    @Table(name = "DOCUMENT")
    @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
    public abstract class Document implements Serializable
    {
    	@Id @GeneratedValue
        @Column(name = "DOCUMENT_ID")
    	private Long id;
    	@Column(name = "DOCUMENT_TITLE")
    	private String title;
    	@Column(name = "DOCUMENT_URL")
    	private String url;
    	@Column(name = "DOCUMENT_DATE_CREATION")
    	private Date creation_in_context;
    	@Column(name = "DOCUMENT_CONTEXT")
    	private String context;
     
     
    	public String getTitle() {
    		return title;
    	}
    	public void setTitle(String title) {
    		this.title = title;
    	}
    	public String getUrl() {
    		return url;
    	}
    	public void setUrl(String url) {
    		this.url = url;
    	}
    	public Date getCreation_in_context() {
    		return creation_in_context;
    	}
    	public void setCreation_in_context(Date creationInContext) {
    		creation_in_context = creationInContext;
    	}
    	public String getContext() {
    		return context;
    	}
    	public void setContext(String context) {
    		this.context = context;
    	}
    	public Long getId() {
    		return id;
    	}
     
    }
    Code de DocumentHTML :
    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
    package fr.natoine.annotations_persistence.document;
     
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.xml.bind.annotation.XmlRootElement;
     
    @XmlRootElement
    @Entity
    public class DocumentHTML extends Document 
    {
    	@Column(name = "DOCUMENTHTML_CONTENT")
    	private String content_html;
     
    	public String getContent_html() {
    		return content_html;
    	}
     
    	public void setContent_html(String contentHtml) {
    		content_html = contentHtml;
    	}
     
    }
    Code de Test :
    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
    package fr.natoine.annotations_persistence.document;
     
    import java.util.Date;
     
    import javax.persistence.EntityManager;
    import javax.persistence.EntityManagerFactory;
    import javax.persistence.EntityTransaction;
    import javax.persistence.Persistence;
     
    import junit.framework.TestCase;
     
    public class DocumentTest extends TestCase
    {
     
    	public DocumentTest(String name) 
    	{
    	    super(name);
    	  }
     
     
    	public void testInsertDocument()
    	{
    		//Créer un document
    		Document _doc = new DocumentHTML();
    		_doc.setContext("test");
    		_doc.setCreation_in_context(new Date());
    		_doc.setTitle("doc de test");
    		_doc.setUrl("url de test");
    		//le rendre persistant
    		EntityManagerFactory emf = Persistence.createEntityManagerFactory("annotation");
            EntityManager em = emf.createEntityManager();
            EntityTransaction tx = em.getTransaction();
            tx.begin();
            em.persist(_doc);
            tx.commit();
            em.close();
    	}
    }
    persistence.xml :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <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="annotation">
          <properties>
              <property name="hibernate.ejb.cfgfile"
                   value="/hibernate.cfg.xml"/>
          </properties>
       </persistence-unit>
    </persistence>
    et hibernate.cfg.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
    67
    68
     
    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
            "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
            "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
     
    <hibernate-configuration>
     
        <session-factory>
     
        	<!-- PostGresql connection settings -->
        <!--	<property name="connection.url">jdbc:postgresql://localhost/firsthibernate</property>
    		<property name="connection.username">postgres</property>
    		<property name="connection.driver_class">org.postgresql.Driver</property>
    		<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
    		<property name="connection.password">p</property>
        -->
    		<!-- MySQL connection settings -->
    		<property name="connection.url">jdbc:mysql://localhost/hibSample</property>
    		<property name="connection.username">hibernate_user</property>
    		<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    		<property name="connection.password">hibernate_pwd</property>
    		<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
     
            <!-- HSQL connection settings -->
            <!-- 
            <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
            <property name="connection.url">jdbc:hsqldb:hsql://localhost</property>
            <property name="connection.username">sa</property>
            <property name="connection.password"></property>
            <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
    		 -->
            <!-- JDBC connection pool (use the built-in) -->
            <property name="connection.pool_size">1</property>
     
            <!-- Enable Hibernate's automatic session context management -->
            <property name="current_session_context_class">thread</property>
     
            <!-- Disable the second-level cache  -->
            <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
     
            <!-- Echo all executed SQL to stdout -->
            <property name="show_sql">true</property>
     
            <!-- Drop and re-create the database schema on startup -->
            <property name="hbm2ddl.auto">update</property>
     
    		<!-- mapping resource -->
    	  	<!-- 
    	    <mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/>
            <mapping resource="org/hibernate/tutorial/domain/Person.hbm.xml"/>
    		 -->
    		 <!-- List of annotated Class -->
    		 <mapping class="fr.natoine.annotations_persistence.selection.Selection"/>
    		 <mapping class="fr.natoine.annotations_persistence.selection.SelectionHTML"/>
    		 <mapping class="fr.natoine.annotations_persistence.annotation.Annotation"/>
    		 <mapping class="fr.natoine.annotations_persistence.annotation.AnnotationDocument"/>
    		 <mapping class="fr.natoine.annotations_persistence.annotation.AnnotationSelection"/>
    		 <mapping class="fr.natoine.annotations_persistence.document.Document"/>
    		 <mapping class="fr.natoine.annotations_persistence.document.DocumentHTML"/>
    		 <mapping class="fr.natoine.annotations_persistence.document.post.Post"/>
    		 <mapping class="fr.natoine.annotations_persistence.document.post.FreeText"/>
    		 <mapping class="fr.natoine.annotations_persistence.document.post.SimpleLabel"/>
     
    		 <mapping class="fr.natoine.user_persistence.User"/>
        </session-factory>
     
    </hibernate-configuration>
    www.natoine.fr
    natoine.developpez.com
    Principalement du Java avec un soupçon de réseaux sociaux.

  2. #2
    Membre éclairé
    Avatar de natoine
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Décembre 2007
    Messages
    393
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Chercheur en informatique

    Informations forums :
    Inscription : Décembre 2007
    Messages : 393
    Par défaut
    Maven en console me crache :
    -------------------------------------------------------
    T E S T S
    -------------------------------------------------------
    Running fr.natoine.annotations_persistence.document.DocumentTest
    2 [main] INFO org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.4.0.GA
    12 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
    24 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
    27 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
    30 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
    96 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.1.0.GA
    99 [main] INFO org.hibernate.ejb.Version - Hibernate EntityManager 3.4.0.GA
    383 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
    383 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
    453 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
    543 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: fr.natoine.annotations_persistence.selection.Selection
    622 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity fr.natoine.annotations_persistence.selection.Selection on table SELECTION
    Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.857 sec <<< FAILURE!

    Results :

    Failed tests:
    testInsertDocument(fr.natoine.annotations_persistence.document.DocumentTest)

    Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
    Il fait référence à une classe dans laquelle j'ai un attribut de type Document.
    Le code de cette classe est :
    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
    package fr.natoine.annotations_persistence.selection;
     
    import java.io.Serializable;
    import java.util.Date;
     
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.Inheritance;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.MappedSuperclass;
    import javax.persistence.Table;
    import javax.persistence.InheritanceType;
    import javax.xml.bind.annotation.XmlRootElement;
     
    import fr.natoine.annotations_persistence.document.Document;
    import fr.natoine.user_persistence.User;
     
    @XmlRootElement
    @Entity
    @MappedSuperclass
    @Table(name = "SELECTION")
    @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
    public abstract class Selection implements Serializable 
    {
    	@Id @GeneratedValue
    	@Column(name = "SELECTION_ID")
    	protected Long id;
    	@Column(name = "SELECTION_URL_SOURCE")
    	private String url_source;
    	@Column(name = "SELECTION_BEGIN")
    	private String begin;
    	@Column(name = "SELECTION_END")
    	private String end;
    	@ManyToOne(cascade = CascadeType.ALL, targetEntity = Document.class)
    	@JoinColumn(name = "DOCUMENT_ID")
    	private Document selection_origin;
    	@Column(name = "SELECTION_CONTEXT")
    	private String context;
    	@ManyToOne(cascade = CascadeType.ALL, targetEntity = User.class)
    	@JoinColumn(name = "USER_ID")
    	private User author;
    	@Column(name = "SELECTION_CREATION")
    	private Date creation;
     
    	public Selection() {
    	}
     
    	public Long getId() {
    		return id;
    	}
     
    	public String getUrl_source() {
    		return url_source;
    	}
     
    	public void setUrl_source(String urlSource) {
    		url_source = urlSource;
    	}
     
    	public String getBegin() {
    		return begin;
    	}
     
    	public void setBegin(String begin) {
    		this.begin = begin;
    	}
     
    	public String getEnd() {
    		return end;
    	}
     
    	public void setEnd(String end) {
    		this.end = end;
    	}
     
    	public Document getSelection_origin() {
    		return selection_origin;
    	}
     
    	public void setSelection_origin(Document selectionOrigin) {
    		selection_origin = selectionOrigin;
    	}
     
    	public User getAuthor() {
    		return author;
    	}
     
    	public void setAuthor(User author) {
    		this.author = author;
    	}
     
    	public String getContext() {
    		return context;
    	}
     
    	public void setContext(String context) {
    		this.context = context;
    	}
     
    	public Date getCreation() {
    		return creation;
    	}
     
    	public void setCreation(Date creation) {
    		this.creation = creation;
    	}
    }
    www.natoine.fr
    natoine.developpez.com
    Principalement du Java avec un soupçon de réseaux sociaux.

  3. #3
    Membre éclairé
    Avatar de natoine
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Décembre 2007
    Messages
    393
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Chercheur en informatique

    Informations forums :
    Inscription : Décembre 2007
    Messages : 393
    Par défaut
    Je comprends vraiment pas d'ou vient le problème.
    J'ai mis mon mapping de Selection en commentaire dans hibernat.cfg.xml
    Du coup j'ai la même erreur avec binding entity Document

    Mais ça ne marche toujours pas...
    J'ai vraiment besoin d'aide là
    www.natoine.fr
    natoine.developpez.com
    Principalement du Java avec un soupçon de réseaux sociaux.

  4. #4
    Membre éclairé
    Avatar de natoine
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Décembre 2007
    Messages
    393
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Chercheur en informatique

    Informations forums :
    Inscription : Décembre 2007
    Messages : 393
    Par défaut
    C'est bon j'ai viré l'annotation en trop : @MappedSuperclass
    www.natoine.fr
    natoine.developpez.com
    Principalement du Java avec un soupçon de réseaux sociaux.

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

Discussions similaires

  1. conflit d'inclusions et Héritage de classe
    Par gedeon555 dans le forum C++
    Réponses: 7
    Dernier message: 01/10/2006, 19h48
  2. [POO] Problème héritage des classes PHP4
    Par zana74 dans le forum Langage
    Réponses: 2
    Dernier message: 15/08/2006, 16h00
  3. Héritage de classes.
    Par Berzerk_ dans le forum C++
    Réponses: 48
    Dernier message: 13/08/2006, 23h48
  4. [POO] Héritage vs classe dans une classe
    Par robichou dans le forum Langage
    Réponses: 4
    Dernier message: 06/08/2006, 23h51
  5. [OO] Héritage - Mixins Classes
    Par djmalo dans le forum Langages de programmation
    Réponses: 4
    Dernier message: 01/03/2005, 23h16

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