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 :

problème avec la persistance des objets


Sujet :

Hibernate Java

Vue hybride

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

    Informations forums :
    Inscription : Juin 2003
    Messages : 172
    Par défaut problème avec la persistance des objets
    Bonjour tout le monde,

    Je travaille à partir d'un tutoriel pour apprendre hibernate, c'est le tutoriel de julien DEFAUT.

    J'ai suivi methodiquement, j'ai configuré correctement hibernate.

    Mais lors de la compilation de cette page j'ai cette erreur qui est générée:
    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
    3 avr. 2007 11:33:50 net.sf.hibernate.cfg.Environment <clinit>
    INFO: Hibernate 2.1.6
    3 avr. 2007 11:33:50 net.sf.hibernate.cfg.Environment <clinit>
    INFO: hibernate.properties not found
    3 avr. 2007 11:33:50 net.sf.hibernate.cfg.Environment <clinit>
    INFO: using CGLIB reflection optimizer
    3 avr. 2007 11:33:50 net.sf.hibernate.cfg.Configuration configure
    INFO: configuring from resource: /hibernate.cfg.xml
    3 avr. 2007 11:33:50 net.sf.hibernate.cfg.Configuration getConfigurationInputStream
    INFO: Configuration resource: /hibernate.cfg.xml
    3 avr. 2007 11:33:52 net.sf.hibernate.cfg.Configuration doConfigure
    INFO: Configured SessionFactory: null
    3 avr. 2007 11:33:52 net.sf.hibernate.cfg.Configuration secondPassCompile
    INFO: processing one-to-many association mappings
    3 avr. 2007 11:33:52 net.sf.hibernate.cfg.Configuration secondPassCompile
    INFO: processing one-to-one association property references
    3 avr. 2007 11:33:52 net.sf.hibernate.cfg.Configuration secondPassCompile
    INFO: processing foreign key constraints
    3 avr. 2007 11:33:52 net.sf.hibernate.cfg.SettingsFactory buildSettings
    ATTENTION: No dialect set - using GenericDialect: Dialect class not found: org.hibernate.dialect.MySQLDialect
    3 avr. 2007 11:33:52 net.sf.hibernate.dialect.Dialect <init>
    INFO: Using dialect: net.sf.hibernate.dialect.GenericDialect
    3 avr. 2007 11:33:52 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Use outer join fetching: true
    3 avr. 2007 11:33:52 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: Using Hibernate built-in connection pool (not for production use!)
    3 avr. 2007 11:33:52 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: Hibernate connection pool size: 20
    3 avr. 2007 11:33:52 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost/Base1
    3 avr. 2007 11:33:52 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: connection properties: {user=root}
    3 avr. 2007 11:33:52 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
    INFO: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
    3 avr. 2007 11:33:52 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Use scrollable result sets: true
    3 avr. 2007 11:33:52 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Use JDBC3 getGeneratedKeys(): true
    3 avr. 2007 11:33:52 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Optimize cache for minimal puts: false
    3 avr. 2007 11:33:52 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Query language substitutions: {}
    3 avr. 2007 11:33:52 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: cache provider: net.sf.hibernate.cache.EhCacheProvider
    3 avr. 2007 11:33:52 net.sf.hibernate.cfg.Configuration configureCaches
    INFO: instantiating and configuring caches
    3 avr. 2007 11:33:53 net.sf.hibernate.impl.SessionFactoryImpl <init>
    INFO: building session factory
    3 avr. 2007 11:33:56 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
    INFO: Not binding factory to JNDI, no JNDI name configured
    Exception in thread "main" net.sf.hibernate.MappingException: No persister for: com.minosis.hibernate.TContact
    	at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:347)
    	at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2690)
    	at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2697)
    	at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:763)
    	at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
    	at Test.main(Test.java:16)
    Le code que je compile est celui ci:
    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
     
    import net.sf.hibernate.*;
    import com.minosis.hibernate.*;
    import com.minosis.bdd.*;
    public class Test {
     
    public static void main(String[] args) throws HibernateException
    {
    	Session session=HibernateUtil.currentSession();
    	Transaction tx=session.beginTransaction();
     
    	TContact contact=new TContact();
    	contact.setNom("Dupont");
    	contact.setPrenom("Jean");
    	contact.setAge(new Integer(33));
    	session.save(contact);
    /*	
    	contact=new TContact();
    	contact.setNom("Lambert");
    	contact.setPrenom("Julie");
    	contact.setAge(new Integer(27));
    	session.save(contact);
    */
    	tx.commit();
    	HibernateUtil.closeSession();
    }
    }
    Je vous remercie de votre aide

  2. #2
    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
    Apparement il te dit que tu n'as pas creer cette classe :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    com.minosis.hibernate.TContact
    As-tu creer la classe TContact?
    As-tu creer le mapping?
    L'as-tu ecris dans ton fichier de configuration?

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    172
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 172
    Par défaut
    Je te remercie de ta réponse aussi rapide.

    J'ai bien créé la classe TContact, elle fait partie du package com.minosis.hibernate.

    Je te donne le code:
    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
    package com.minosis.hibernate;
     
    import com.minosis.hibernate.base.BaseTContact;
     
    /**
     * This is the object class that relates to the t_contact table.
     * Any customizations belong here.
     */
    public class TContact extends BaseTContact {
     
    /*[CONSTRUCTOR MARKER BEGIN]*/
    	public TContact () {
    		super();
    	}
     
    	/**
             * Constructor for primary key
             */
    	public TContact (java.lang.Integer _id) {
    		super(_id);
    	}
     
    /*[CONSTRUCTOR MARKER END]*/
    }
    J'ai bien créé mon mapping:
    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
    <?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="com.minosis.hibernate.TContact" table="t_contact">
     <id name="id" type="integer">
      <column name="id" sql-type="int(11)"/>
      <generator class="increment"/>
     </id>
     <property name="Nom" type="string">
      <column name="nom" sql-type="varchar(50)" not-null="true"/>
     </property>
     <property name="Prenom" type="string">
      <column name="prenom" sql-type="varchar(50)" not-null="true"/>
     </property>
     <property name="Age" type="integer">
      <column name="age" sql-type="int(11)" not-null="true"/>
     </property>
     </class>
    </hibernate-mapping>
    J'ai bien créé mon fichier de configuration le voici:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <?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>
            <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
            <property name="hibernate.connection.url">jdbc:mysql://localhost/Base1</property>
            <property name="hibernate.connection.username">root</property>
            <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        </session-factory>
    </hibernate-configuration>


    NB:J'utilise le SGBDR MySQL et le nom de la base de données est Base1

    Je vous remercie de votre aide.

  4. #4
    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
    Il te faut definir chacun des mappings dans le fichier de configuration

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <mapping resource="la_ou_tu_l_as_range/TContact.hbm.xml"/>
    Jette un oeil sur la doc, tu comprendras certaines choses
    http://www.hibernate.org/hib_docs/v3...iguration.html

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    172
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 172
    Par défaut
    Je te remercie de ton aide.

    Je voudrais savoir, je mets ce bout de code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     <mapping resource="TContact.hbm.xml"/>
    dans ce fichier là?:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <?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>
            <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
            <property name="hibernate.connection.url">jdbc:mysql://localhost/base1</property>
            <property name="hibernate.connection.username">root</property>
            <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        </session-factory>
     
    </hibernate-configuration>
    Si oui à quel emplacement, car là je viens de le mettre après le tag sessionfactory est la il a des erreurs.

    NB:mon fichier "TContact.hbm.xml" est dans le scr
    Je vous remercie de votre aide

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    172
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 172
    Par défaut
    Je voualis vous dire que j'ai résoulu le problème, il m'a bien rentré dans la base les infos.

    Au niveau du fichier de configuration XML, le 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
     
    <?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>
            <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
            <property name="hibernate.connection.url">jdbc:mysql://localhost/base1</property>
            <property name="hibernate.connection.username">root</property>
            <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <mapping resource="TContact.hbm.xml"/> 
        </session-factory>
    </hibernate-configuration>
    Je vous remercie de votre aide.

    Mais lorsque je compile, j'ai des erreurs qui s'affiche
    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
    3 avr. 2007 14:23:01 net.sf.hibernate.cfg.Environment <clinit>
    INFO: Hibernate 2.1.6
    3 avr. 2007 14:23:01 net.sf.hibernate.cfg.Environment <clinit>
    INFO: hibernate.properties not found
    3 avr. 2007 14:23:01 net.sf.hibernate.cfg.Environment <clinit>
    INFO: using CGLIB reflection optimizer
    3 avr. 2007 14:23:01 net.sf.hibernate.cfg.Configuration configure
    INFO: configuring from resource: /hibernate.cfg.xml
    3 avr. 2007 14:23:01 net.sf.hibernate.cfg.Configuration getConfigurationInputStream
    INFO: Configuration resource: /hibernate.cfg.xml
    3 avr. 2007 14:23:03 net.sf.hibernate.cfg.Configuration addResource
    INFO: Mapping resource: TContact.hbm.xml
    3 avr. 2007 14:23:06 net.sf.hibernate.cfg.Binder bindRootClass
    INFO: Mapping class: com.minosis.hibernate.TContact -> t_contact
    3 avr. 2007 14:23:06 net.sf.hibernate.cfg.Configuration doConfigure
    INFO: Configured SessionFactory: null
    3 avr. 2007 14:23:06 net.sf.hibernate.cfg.Configuration secondPassCompile
    INFO: processing one-to-many association mappings
    3 avr. 2007 14:23:06 net.sf.hibernate.cfg.Configuration secondPassCompile
    INFO: processing one-to-one association property references
    3 avr. 2007 14:23:06 net.sf.hibernate.cfg.Configuration secondPassCompile
    INFO: processing foreign key constraints
    3 avr. 2007 14:23:06 net.sf.hibernate.cfg.SettingsFactory buildSettings
    ATTENTION: No dialect set - using GenericDialect: Dialect class not found: org.hibernate.dialect.MySQLDialect
    3 avr. 2007 14:23:06 net.sf.hibernate.dialect.Dialect <init>
    INFO: Using dialect: net.sf.hibernate.dialect.GenericDialect
    3 avr. 2007 14:23:06 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Use outer join fetching: true
    3 avr. 2007 14:23:06 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: Using Hibernate built-in connection pool (not for production use!)
    3 avr. 2007 14:23:06 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: Hibernate connection pool size: 20
    3 avr. 2007 14:23:06 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost/base1
    3 avr. 2007 14:23:06 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: connection properties: {user=root}
    3 avr. 2007 14:23:06 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
    INFO: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
    3 avr. 2007 14:23:09 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Use scrollable result sets: true
    3 avr. 2007 14:23:09 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Use JDBC3 getGeneratedKeys(): true
    3 avr. 2007 14:23:09 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Optimize cache for minimal puts: false
    3 avr. 2007 14:23:09 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: Query language substitutions: {}
    3 avr. 2007 14:23:09 net.sf.hibernate.cfg.SettingsFactory buildSettings
    INFO: cache provider: net.sf.hibernate.cache.EhCacheProvider
    3 avr. 2007 14:23:09 net.sf.hibernate.cfg.Configuration configureCaches
    INFO: instantiating and configuring caches
    3 avr. 2007 14:23:09 net.sf.hibernate.impl.SessionFactoryImpl <init>
    INFO: building session factory
    3 avr. 2007 14:23:12 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
    INFO: Not binding factory to JNDI, no JNDI name configured
    je voudrais savoir comment ca se fait.

    Je vous remercie de votre aide

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

Discussions similaires

  1. Réponses: 0
    Dernier message: 11/10/2012, 18h35
  2. Réponses: 14
    Dernier message: 04/10/2012, 13h14
  3. Réponses: 10
    Dernier message: 10/10/2009, 18h39
  4. [Problèmes avec ArrayList] Supprimer des objets égaux à null
    Par smutmutant2003 dans le forum Collection et Stream
    Réponses: 5
    Dernier message: 08/10/2009, 10h43
  5. Réponses: 11
    Dernier message: 16/12/2003, 19h58

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