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 :

[mapping] problème de configuration


Sujet :

Hibernate Java

Vue hybride

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

    Informations forums :
    Inscription : Juin 2007
    Messages : 55
    Par défaut [mapping] problème de configuration
    Bonjour tout le monde,
    j'ai suivi le tuto de developpez pour hibernate histoire de me faire la main, et ça fonctionne très bien. Alors, hop, tout fringant, je cherche à adapter ça à mon projet
    Mais voilà, j'obtiens (et n'arrive pas à dépasser, d'où ce post) toujours cette exception, après test d'insertion d'un objet Procedure dans la BD:

    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
    Initial SessionFactory creation failed. org.hibernate.MappingException: invalid configuration
    Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
    	at hibernate.HibernateUtil.<clinit>(HibernateUtil.java:23)
    	at parser.SaveToBD.savetoBD(SaveToBD.java:112)
    	at fenetre.FileMenu.actionPerformed(FileMenu.java:199)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.AbstractButton.doClick(Unknown Source)
    	at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
    	at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: org.hibernate.MappingException: invalid configuration
    	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1487)
    	at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
    	at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
    	at hibernate.HibernateUtil.<clinit>(HibernateUtil.java:19)
    	... 29 more
    Caused by: org.xml.sax.SAXParseException: The content of element type "session-factory" is incomplete, it must match "(property*,mapping+,(class-cache|collection-cache|jcs-class-cache|jcs-collection-cache)*)".
    	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.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.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:1484)
    Du coup je me dis que ça vient de mon fichier de mapping que voici:

    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"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    	"-//Hibernate/Hibernate Mapping DTD//EN"
    	"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
     
    <hibernate-mapping >
    	<class name="hibernate.Procedure" table="procedure">
     
    		<id 
    			name="IdProc" type="integer">
    			<column name="idProc" not-null="true"/>
     			<generator class="increment"/>
     		</id>
     
     		<property
    			column="nameProc"
    			length="80"
    			name="NameProc"
    			not-null="true"
    			type="String"
    		 />
     
    		<property
    			name="LastModification"
    			column="lastModification"
    			not-null="true"
    			type="timestamp"
    		 />
     
    		<property
    			name="IdMission"
    			column="idMission"
    			not-null="true"
    			type="integer"
    		 />	
     
    		<property
    			name="File"
    			column="file"
    			type="binary"
    		 />
     
    	</class>
    </hibernate-mapping>
    Est-ce qu'il faut que je précise dans le fichier de configuration d'hibernate où se trouve le fichier de mapping (avec une balise resource)?
    J'avoue rester perplexe... Je vous mets le fichier de config.xml au cas où:

    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
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-configuration
        PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
     
    <hibernate-configuration>
    	<session-factory>
    		<!-- local connection properties -->
    		<property name="hibernate.connection.url">
    			jdbc:mysql://127.0.0.1:3306/base
    		</property>
    		<property name="hibernate.connection.driver_class">
    			com.mysql.jdbc.Driver
    		</property>
    		<property name="hibernate.connection.username">user</property>
    		<property name="hibernate.connection.password">user</property>
    		<!-- property name="hibernate.connection.pool_size"></property -->
     
    		<!-- dialect for MySQL -->
    		<property name="dialect">
    			org.hibernate.dialect.MySQLDialect
    		</property>
     
    		<property name="hibernate.show_sql">true</property>
    		<property name="hibernate.use_outer_join">true</property>
    		<!-- <property name="hibernate.transaction.factory_class">
    			net.sf.hibernate.transaction.JTATransactionFactory
    			</property>
    			<property name="jta.UserTransaction">
    			java:comp/UserTransaction
    			</property>-->
    		<property name="hibernate.transaction.factory_class">
    			org.hibernate.transaction.JDBCTransactionFactory
    		</property>
    	</session-factory>
    </hibernate-configuration>
    N'hésitez pas à me demander plus de précisions si vous le souhaitez.
    Merci de votre aide.

  2. #2
    Membre Expert
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 276
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 276
    Par défaut
    Tu dois définir dans ton fichier de conf: hibernate.cfg.xlm, les classes que tu as mappées avec la balise mapping:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <mapping resource="tonPackage/TaClasse.hbm.xml"

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    55
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 55
    Par défaut
    merci beaucoup! ça marche .
    Enfin presque...
    J'obtiens une nouvelle erreur (mais ça avance) :
    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
    Hibernate: select max(idProc) from procedure
    Exception in thread "AWT-EventQueue-0" org.hibernate.exception.SQLGrammarException: could not fetch initial value for increment generator
    	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
    	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    	at org.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:107)
    	at org.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:44)
    	at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:99)
    	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
    	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
    	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
    	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
    	at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
    	at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
    	at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:495)
    	at parser.SaveToBD.savetoBD(SaveToBD.java:114)
    	at fenetre.FileMenu.actionPerformed(FileMenu.java:199)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.AbstractButton.doClick(Unknown Source)
    	at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
    	at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Or, d'après le tutoriel, il suffit de déclarer dans le fichier de mapping que idProc est un identifiant (avec la balise <id>) pour qu'hibernate s'en occupe... Il me manque quelque chose Je précise qu'il n'y a encore rien dans la table procédure (j'essaie simplement d'insérer via hibernate pour l'instant), donc je veux bien comprendre qu'il ne ressort rien de la commande:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    select max(idProc) from procedure
    Mais je ne comprends pas pourquoi il la lance. Merci par avance de votre aide.

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    55
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 55
    Par défaut
    Apparemment, le problème vient de la requête en elle-même, qui devrait être:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    select max(idProc) from 'procedure'
    et non:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    select max(idProc) from procedure
    Une idée en ce qui concerne ces quotes non présents dans la reqête formée par hibernate?
    Je continue de chercher.

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    55
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 55
    Par défaut
    Hop, après avoir rajouté des backsticks (et non des quotes!) autour du nom de la table dans le fichier de mapping, la reqûete d'insertion s'effectue sans problème.
    Par contre je ne m'explique pas pourquoi ces backsticks ne sont pas nécessaires dans le tuto de developpez (je suis sous phpMyAdmin) alors qu'avec mes tables ils le sont

    Enfin, ça marche, c'est l'essentiel (mais j'aime pas trop ne pas avoir compris).
    Bye.

  6. #6
    Membre Expert
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 276
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 276
    Par défaut
    Peut-être que procedure est un mot clef de mysql.
    Essaie en changeant le nom de la table.

  7. #7
    Membre averti
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    55
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 55
    Par défaut
    En effet c'est un mot réservé. En changeant de nom de table, il n'y plus aucun problème!
    Merci fr1man.

  8. #8
    Candidat au Club
    Inscrit en
    Avril 2009
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Avril 2009
    Messages : 2
    Par défaut [Demande d'aide][hibernate]
    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:

    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

    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
     
    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 fciher de mapping associé:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    <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:
    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 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 fcihier de configuration

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

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

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

Discussions similaires

  1. [Install]Problème de configuration d'éclipse
    Par Jean Claude90 dans le forum Eclipse Java
    Réponses: 3
    Dernier message: 26/02/2005, 17h33
  2. [Log4j]petit problème de configuration
    Par mikey_ufc dans le forum Eclipse Java
    Réponses: 3
    Dernier message: 09/01/2005, 23h32
  3. [Tomcat 5 + Eclipse] Problème de configuration
    Par seb55555 dans le forum Tomcat et TomEE
    Réponses: 4
    Dernier message: 26/10/2004, 15h20
  4. [EJB] Problème avec configuration jonas
    Par SteelBox dans le forum JBuilder
    Réponses: 30
    Dernier message: 11/03/2004, 21h30
  5. Problème de configuration
    Par lsdInside dans le forum PostgreSQL
    Réponses: 4
    Dernier message: 09/10/2003, 12h34

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