2017-06-27 4 views
-1

Je cours mon premier projet de mise en veille prolongée qui enregistre des informations utilisateur comme identifiant, nom et adresse dans la base de données MySQLJe reçois org.hibernate.InvalidMappingException: Impossible de lire XML lors de l'exécution simple projet de mise en veille prolongée

C'est mon erreur log

log4j:WARN No appenders could be found for logger (org.jboss.logging). 
log4j:WARN Please initialize the log4j system properly. 
Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML 
    at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:109) 
    at org.hibernate.cfg.Configuration.add(Configuration.java:490) 
    at org.hibernate.cfg.Configuration.add(Configuration.java:486) 
    at org.hibernate.cfg.Configuration.add(Configuration.java:659) 
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:742) 
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2197) 
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2169) 
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2149) 
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2102) 
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2017) 
    at mypack.DataInsertion.insertInfo(DataInsertion.java:18) 
    at mypack.DataInsertion.main(DataInsertion.java:11) 
Caused by: org.dom4j.DocumentException: Error on line 3 of document : The processing instruction target matching "[xX][mM][lL]" is not allowed. Nested exception: The processing instruction target matching "[xX][mM][lL]" is not allowed. 
    at org.dom4j.io.SAXReader.read(SAXReader.java:482) 
    at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:78) 
    ... 11 more 

hibernate.cfg.xml (Configuration du fichier xml)

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE hibernate-configuration PUBLIC 
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 
<hibernate-configuration> 
    <session-factory> 

<!-- Related to the connection START --> 
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property> 
    <property name="connection.url">jdbc:mysql://localhost:3306/hibdb</property> 
    <property name="connection.user">root</property> 
    <property name="connection.password">admin</property> 
<!-- Related to the connection END -->  

<!-- Related to the hibernate properties START --> 
    <property name="show_sql">true</property> 
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property> 
<!-- Related to the hibernate properties END -->  

<!-- List of XML mapping files --> 
    <mapping resource="user.hbm.xml"/> 

</session-factory> 
</hibernate-configuration> 

user.hbm.xml (Mapping xml)

<!-- Mapping File to POJO Class --> 

<?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> 

<class name="mypack.DataProvider" table="user_info"> 
<id name="user_id" column="table_id"> 
<generator class="assigned"/> 
</id> 

<property name="user_name" column = "name" /> 
<property name="user_address" column = "address" /> 

</class> 

</hibernate-mapping> 

DataProvider.java (classe POJO)

// POJO Classe

package mypack; 

public class DataProvider { 

private int user_id; 
private String user_name; 
private String user_address; 

public int getUser_id() { 
    return user_id; 
} 
public void setUser_id(int user_id) { 
    this.user_id = user_id; 
} 
public String getUser_name() { 
    return user_name; 
} 
public void setUser_name(String user_name) { 
    this.user_name = user_name; 
} 
public String getUser_address() { 
    return user_address; 
} 
public void setUser_address(String user_address) { 
    this.user_address = user_address; 
} 

} 

DataInsertion.java (implentation java class)

package mypack; 

import org.hibernate.Session; 
import org.hibernate.SessionFactory; 
import org.hibernate.Transaction; 
import org.hibernate.cfg.Configuration; 

public class DataInsertion { 

    public static void main(String[] args) { 
     new DataInsertion().insertInfo(); 

    } 

    public void insertInfo() 
    { 
     Configuration con = new Configuration();  //interation with hib 
     con.configure("hibernate.cfg.xml");   //registering to xml 

     SessionFactory SF = con.buildSessionFactory(); //creating session 
     Session session = SF.openSession();   //opening new session 
     DataProvider provider = new DataProvider(); 
     provider.setUser_id(1); 
     provider.setUser_name("Goutham"); 
     provider.setUser_address("Hunsur"); 

     Transaction TR = session.beginTransaction(); 
     session.save(provider); 
     System.out.println("Object saved successfully"); 
     TR.commit();         //saving transaction 
     session.close(); 
     SF.close(); 
    } 

} 

S'il vous plaît me conseiller ,,, Merci.

Répondre

0

Essayez de supprimer la ligne de commentaire et ligne vide avant la première balise dans user.hbm.xml

+0

Je suis arrivé ce journal d'erreur après avoir corrigé cette question: –

+0

log4j: WARN Aucun appenders n'a pu être trouvée pour enregistreur (org. jboss.logging). log4j: WARN Veuillez initialiser correctement le système log4j. Objet enregistré avec succès Hibernate: insérer dans user_info (nom, adresse, ID_table) valeurs (?,?,?) Exception dans le fil "principal" org.hibernate.exception.SQLGrammarException: impossible d'exécuter la commande –

+0

Désolé, j'ai obtenu le droit output, insert dans user_info (nom, adresse, id_table), ici id_table devrait être juste id. –