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 :

[3.1] InvalidMappingException


Sujet :

Hibernate Java

Vue hybride

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

    Informations forums :
    Inscription : Mars 2007
    Messages : 12
    Par défaut [3.1] InvalidMappingException
    Bonjour,

    voici ma base de donnée, j'aimerai avoir le mapping xml correspondant :
    J'utilise hibernate 3.1


    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
    create table adherent (
       adh_id               SERIAL               not null,
       grp_id               INT4                 null,
       adh_nom              VARCHAR(100)         null,
       adh_prenom           VARCHAR(100)         null,
       constraint PK_ADHERENT primary key (adh_id)
    );
     
    create table groupe (
       grp_id               SERIAL               not null,
       grp_lib              VARCHAR(50)          null,
       constraint PK_GROUPE primary key (grp_id)
    );
     
    alter table adherent
       add constraint FK_ADHERENT_REFERENCE_GROUPE foreign key (grp_id)
          references groupe (grp_id)
          on delete restrict on update restrict;
    J'ai essayé ceci mais ca ne marche pas :

    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
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
          "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
              "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping package="bean">
       <class name="adherent" 
              table="adherent" node="texte">
           <id name="adh_id" node="adh_id"/>
           <property name="adh_nom" node="adh_nom"/>
           <property name="adh_prenom" node="adh_prenom"/>
     
           <set name="groupe" cascade="all">
                <key column="grp_id" />
                <one-to-many class="groupe" />
            </set>
     
       </class>
       <class name="groupe">
           <id name="grp_id" node="grp_id"/>
           <property name="grp_lib" node="grp_lib"/>
        </class>
    </hibernate-mapping>
    Il y a surement quelque chose que je ne fais pas correctement. Merci d votre aide.

    Pour info je veux à partir d'un ficheir xml alimenter plusieurs tables de la base de donnée.

  2. #2
    Membre éprouvé
    Avatar de moritan
    Homme Profil pro
    Développeur Java
    Inscrit en
    Juin 2005
    Messages
    687
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Juin 2005
    Messages : 687
    Par défaut
    Citation Envoyé par BruteDuCafeDesSports

    J'ai essayé ceci mais ca ne marche pas :
    Tu as quoi exactement comme problème ?
    Un message d'erreur à nous donner?

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 12
    Par défaut
    Voici mon message d'erreur correspondant :

    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
    23 mars 2007 18:16:17 org.hibernate.cfg.Environment <clinit>
    INFO: Hibernate 3.2.2
    23 mars 2007 18:16:17 org.hibernate.cfg.Environment <clinit>
    INFO: hibernate.properties not found
    23 mars 2007 18:16:17 org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: Bytecode provider name : cglib
    23 mars 2007 18:16:17 org.hibernate.cfg.Environment <clinit>
    INFO: using JDK 1.4 java.sql.Timestamp handling
    23 mars 2007 18:16:17 org.hibernate.cfg.Configuration addResource
    INFO: Reading mappings from resource : mappingXML/rcp.hbm.xml
    23 mars 2007 18:16:17 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: bean.adherent -> adherent
    23 mars 2007 18:16:18 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: bean.groupe -> groupe
    23 mars 2007 18:16:18 org.hibernate.cfg.Configuration configure
    INFO: configuring from resource: /hibernate.cfg.xml
    23 mars 2007 18:16:18 org.hibernate.cfg.Configuration getConfigurationInputStream
    INFO: Configuration resource: /hibernate.cfg.xml
    23 mars 2007 18:16:18 org.hibernate.cfg.Configuration addResource
    INFO: Reading mappings from resource : Adherent.hbm.xml
    23 mars 2007 18:16:18 org.hibernate.util.XMLHelper$ErrorLogger error
    GRAVE: Error parsing XML: XML InputStream(50) The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".
    Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource Adherent.hbm.xml
    	at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
    	at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
    	at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
    	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
    	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
    	at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
    	at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
    	at MappingXML.<init>(MappingXML.java:30)
    	at MappingXML.main(MappingXML.java:135)
    Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from invalid mapping
    	at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:502)
    	at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
    	... 8 more
    Caused by: org.xml.sax.SAXParseException: The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".
    	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
    	at org.dom4j.io.SAXReader.read(SAXReader.java:339)
    	at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:499)
    	... 9 more

  4. #4
    Membre éprouvé
    Avatar de moritan
    Homme Profil pro
    Développeur Java
    Inscrit en
    Juin 2005
    Messages
    687
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Juin 2005
    Messages : 687
    Par défaut
    Vu le message d'erreur il semblerait que ton fichier Adherent.hbm.xml ne soit pas valide, (balise class) est-ce celui que tu nous as donné?

  5. #5
    Membre Expert Avatar de willoi
    Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    1 355
    Détails du profil
    Informations personnelles :
    Âge : 52
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 355
    Par défaut
    tu ecris adherent dans class et tu as declare bean comme package plus haut cela suppose que tu as cree une classe bean.adherent

    Est-ce le cas ?
    Si non qu'as tu cree?

  6. #6
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 12
    Par défaut
    Tout a fait willoi, etant donné que pour alimenter ma base de donnée depuis un fichier xml je lui passe un fichier xml (mappingXML/Adherent.hbm.xml) et une classe (bean.Adherent)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    public MappingXML(String file){
     
    		Configuration cfg = new Configuration()
    			.addResource(file) ;
     
    		cfg.configure() ;
    		sessionFactory = cfg.buildSessionFactory();
    	}
    Je vous joins le code de ma fonction d'alimentation
    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
    public void insertXML(String file, String mapping, String XPath) {
     
    		SAXReader sr ;
    		Document doc ;
     
    		doc = null ;
    		sr = new SAXReader(false) ;
     
    		try {
    			doc = sr.read(file) ;
    			//doc = sr.read(ClassLoader.getSystemClassLoader().getResourceAsStream("rcp_thyroide.xml"));
    		} catch (DocumentException e1) {
    			log.log(Level.SEVERE, e1.getMessage());
    			e1.printStackTrace();
    		} 
     
    		List todo=doc.selectNodes(XPath);
     
    		Session session = sessionFactory.openSession();
    		Session xmlSession = session.getSession(EntityMode.DOM4J);
    		Transaction tx=session.beginTransaction();
     
    		for (Iterator it=todo.iterator(); it.hasNext(); ) {
    			xmlSession.saveOrUpdate(mapping,it.next());
    		}
     
    		tx.commit();
    		session.close();
    	}
    Dans ma fonction main
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    MappingXML mapxml_Thyroide = new MappingXML("mappingXML/adh.hbm.xml");
     
    mapxml_Thyroide.insertXML(mon_fichier_xml, "bean.adherent", "//texte");
    et mon fichier mappingXML/adh.hbm.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
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
          "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
              "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping package="bean">
       <class name="adherent" 
              table="adherent" node="texte">
           <id name="adh_id" node="adh_id"/>
           <property name="adh_nom" node="adh_nom"/>
           <property name="adh_prenom" node="adh_prenom"/>
     
           <set name="groupe" cascade="all">
                <key column="grp_id" />
                <one-to-many class="groupe" />
            </set>
     
       </class>
       <class name="groupe">
           <id name="grp_id" node="grp_id"/>
           <property name="grp_lib" node="grp_lib"/>
        </class>
    </hibernate-mapping>
    et mon fichier bean.adherent
    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
    package bean;
     
    public class adherent {
    	protected String adh_id;
    	protected String adh_nom;
    	protected String adh_prenom;
    	protected String grp_id;
     
    	/**
             * @return the adh_nom
             */
    	public String getAdh_nom() {
    		return adh_nom;
    	}
    	/**
             * @param adh_nom the adh_nom to set
             */
    	public void setAdh_nom(String adh_nom) {
    		this.adh_nom = adh_nom;
    	}
    	/**
             * @return the adh_prenom
             */
    	public String getAdh_prenom() {
    		return adh_prenom;
    	}
    	/**
             * @param adh_prenom the adh_prenom to set
             */
    	public void setAdh_prenom(String adh_prenom) {
    		this.adh_prenom = adh_prenom;
    	}
    	/**
             * @return the adh_id
             */
    	public String getAdh_id() {
    		return adh_id;
    	}
    	/**
             * @param adh_id the adh_id to set
             */
    	public void setAdh_id(String adh_id) {
    		this.adh_id = adh_id;
    	}
    	/**
             * @return the grp_id
             */
    	public String getGrp_id() {
    		return grp_id;
    	}
    	/**
             * @param grp_id the grp_id to set
             */
    	public void setGrp_id(String grp_id) {
    		this.grp_id = grp_id;
    	}
    }
    Et voici mon message d'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
    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
     
    2 avr. 2007 15:12:19 org.hibernate.cfg.Environment <clinit>
    INFO: Hibernate 3.2.2
    2 avr. 2007 15:12:19 org.hibernate.cfg.Environment <clinit>
    INFO: hibernate.properties not found
    2 avr. 2007 15:12:19 org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: Bytecode provider name : cglib
    2 avr. 2007 15:12:19 org.hibernate.cfg.Environment <clinit>
    INFO: using JDK 1.4 java.sql.Timestamp handling
    2 avr. 2007 15:12:19 org.hibernate.cfg.Configuration addResource
    INFO: Reading mappings from resource : mappingXML/adh.hbm.xml
    2 avr. 2007 15:12:20 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: bean.adherent -> adherent
    2 avr. 2007 15:12:20 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: bean.groupe -> groupe
    2 avr. 2007 15:12:20 org.hibernate.cfg.Configuration configure
    INFO: configuring from resource: /hibernate.cfg.xml
    2 avr. 2007 15:12:20 org.hibernate.cfg.Configuration getConfigurationInputStream
    INFO: Configuration resource: /hibernate.cfg.xml
    2 avr. 2007 15:12:20 org.hibernate.cfg.Configuration addResource
    INFO: Reading mappings from resource : Adherent.hbm.xml
    2 avr. 2007 15:12:20 org.hibernate.util.XMLHelper$ErrorLogger error
    GRAVE: Error parsing XML: XML InputStream(43) The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".
    Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource Adherent.hbm.xml
    	at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
    	at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
    	at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
    	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
    	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
    	at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
    	at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
    	at MappingXML.<init>(MappingXML.java:31)
    	at MappingXML.main(MappingXML.java:136)
    Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from invalid mapping
    	at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:502)
    	at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
    	... 8 more
    Caused by: org.xml.sax.SAXParseException: The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".
    	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
    	at org.dom4j.io.SAXReader.read(SAXReader.java:339)
    	at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:499)
    	... 9 more
    A mon avis je n'arrive pas à relier les 2 tables adherent et groupe au niveau de mes class, pouvz vous me dire ce que je dois mettre dans les fichiers.

    Merci

Discussions similaires

  1. Réponses: 1
    Dernier message: 14/02/2009, 09h12

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