Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: [mapping][hibernate]
PostPosted: Sun Jan 30, 2011 3:10 pm 
Newbie

Joined: Sun Jan 30, 2011 3:03 pm
Posts: 1
Salut tout le monde, je suis une débutante de l'utilisation d'hibernate j'ai essayée de faire un petit exemple mais j'ai cette exception:
Hello, I am a beginner of using hibernate I tried to make a small example but I have this exception:

Initial SessionFactory creation failed.org.hibernate.MappingException: invalid configuration
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.mql.util.HibernateUtil.<clinit>(HibernateUtil.java:18)
at com.mql.test.TesTHibernate.main(TesTHibernate.java:11)
Caused by: org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1347)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1322)
at com.mql.util.HibernateUtil.<clinit>(HibernateUtil.java:13)
... 1 more
Caused by: org.xml.sax.SAXParseException: Document is invalid: no grammar found.
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.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(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 com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1344)



voilà mes fihciers:
j'ai une classe java bean User
here are my files:
I have a class
Code:

package com.mql.vo;

/**
* @author KhadijaRSS
*
*/
public class User {
   private int idUser;

   private String login;
   private String pass;

   public User() {

   }

   public String getLogin() {
      return login;
   }

   public void setLogin(String login) {
      this.login = login;
   }

   public String getPass() {
      return pass;
   }

   public void setPass(String pass) {
      this.pass = pass;
   }

   public void setIdUser(int idUser) {
      this.idUser = idUser;
   }

   public int getIdUser() {
      return idUser;
   }

}




et le ficher de mapping associé:
and the associated mapping file:
Code:

<hibernate-mapping package="com.mql.vo">
   <class name="User" table="Compte">
      <id name="idUser" column="idCompte">
         <generator class="native"/>
      </id>
      <property name="login" column="login"/>
      <property name="pass" column="password"/>
   </class>
</hibernate-mapping>


une classe de creation d'une session hibernate:
a class to create a Hibernate session:
Code:
package com.mql.util;
import java.io.File;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
    public static final SessionFactory sessionFactory;

    static {
        try {
// Création de la SessionFactory à partir de hibernate.cfg.xml
File f=new File("D:/JAVA/workspace/Test1Hibernate/WebContent/WEB-INF/classes/com/mql/util/hibernate.cfg.xml");
sessionFactory = new Configuration().configure(f).buildSessionFactory();
sessionFactory.openSession();
        } catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

   public static SessionFactory getSessionFactory() {
      return sessionFactory;
   }

}



le fichier de configuration:
configuration file:
Code:
<hibernate-configuration>
   <session-factory>
      
      <!-- Database connection settings -->
      <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="connection.url">
         jdbc:mysql://localhost:3307/mql</property>
      <property name="connection.username">root</property>
      <property name="connection.password">arhid28</property>
      
      <!-- JDBC connection pool (use the built-in) -->
      <property name="connection.pool_size">1</property>
      
      <!-- SQL dialect -->
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <mapping resource="com/mql/vo/User.hbm.xml"/>
      
      <!-- 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">create</property>
      
      
      
   </session-factory>
</hibernate-configuration>

et finalement ma classe de test:
and finally my test class:
Code:

package com.mql.test;
import org.hibernate.Session;
import com.mql.util.HibernateUtil;
import com.mql.vo.User;
public class TesTHibernate {
   public static void main(String[] args) {
      Session session = HibernateUtil.getSessionFactory().getCurrentSession();
      session.beginTransaction();
      User user = new User();
      user.setIdUser(1);
      user.setLogin("khadija");
      user.setPass("khadija");
      session.save(user);
      session.getTransaction().commit();

      HibernateUtil.getSessionFactory().close();
   }
}



Merci d'avance pour votre aide :)
Thank you in advance for your help :)


Top
 Profile  
 
 Post subject: Re: [mapping][hibernate]
PostPosted: Mon Jan 31, 2011 5:42 am 
Regular
Regular

Joined: Fri Jan 28, 2011 11:44 am
Posts: 117
Peut être que ce vieux thread résoudra ton problème:

https://forums.hibernate.org/viewtopic.php?p=2287322&sid=0c18a684dc486ecf3222d637ce39a271


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.