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 :

Message d'erreur Mapping OneToOne [Mapping]


Sujet :

Hibernate Java

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2014
    Messages
    29
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Bénin

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 29
    Points : 31
    Points
    31
    Par défaut Message d'erreur Mapping OneToOne
    Bonjour,

    J'ai un problème avec Hibernate que je ne comprends pas.
    J'ai crée deux classes Personne et DetailPersonne dans mon projet et je voudrais faire le mapping ces classes dans les tables TPersonne et TDetailPersonne de ma base de données.
    Quand j'exécute mon application à partir d'Eclipse voici l'erreur que j'obtiens :
    Toutes mes excuses si ma préoccupation parait bête, en fait je suis totalement nouveau au framework hibernate. C'est mon premier test avec le mapping OneToOne.

    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
     
    16 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
    16 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
    31 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
    31 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
    116 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
    116 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
    209 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : bean/Personne.hbm.xml
    319 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: bean.Personne -> TPersonne
    350 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : bean/DetailPersonne.hbm.xml
    381 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: bean.DetailPersonne -> TDetailPersonne
    Echec creation session factory org.hibernate.InvalidMappingException: Could not parse mapping document from resource bean/DetailPersonne.hbm.xml
    Exception in thread "main" java.lang.ExceptionInInitializerError
    	at util.HibernateUtil.<clinit>(HibernateUtil.java:15)
    	at manager.PersonneManager.ajouterPersonne(PersonneManager.java:12)
    	at test.Main.main(Main.java:16)
    Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource bean/DetailPersonne.hbm.xml
    	at org.hibernate.cfg.Configuration.addResource(Configuration.java:616)
    	at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
    	at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
    	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
    	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
    	at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
    	at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
    	at util.HibernateUtil.<clinit>(HibernateUtil.java:12)
    	... 2 more
    Caused by: org.hibernate.PropertyNotFoundException: field [situationMatrimoniale] not found on bean.DetailPersonne
    	at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:145)
    	at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:137)
    	at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:160)
    	at org.hibernate.util.ReflectHelper.getter(ReflectHelper.java:241)
    	at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:229)
    	at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:302)
    	at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2193)
    	at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2170)
    	at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2060)
    	at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:381)
    	at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:295)
    	at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:166)
    	at org.hibernate.cfg.Configuration.add(Configuration.java:716)
    	at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:551)
    	at org.hibernate.cfg.Configuration.addResource(Configuration.java:613)
    	... 9 more

    Fichier hibernate.cfg.xml généré:

    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
     
    <?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="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://localhost:3306/bd_personne</property>
    <property name="connection.username">root</property>
    <property name="connection.password"></property>
     
    <property name="connection.pool_size">1</property>
     
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
     
    <property name="current_session_context_class">thread</property>
     
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
     
    <property name="show_sql">true</property>
     
    <property name="hbm2ddl.auto">update</property>
     
    <mapping resource="bean/Personne.hbm.xml" />
    <mapping resource="bean/DetailPersonne.hbm.xml" />
     
    </session-factory>
    </hibernate-configuration>

    Fichier Personne.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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
     
    <hibernate-mapping>
    <class name="bean.Personne" table="TPersonne">
    <id name="idPersonne" column="idPersonne">
    <generator class="increment" />
    </id>
    <property name="nomPersonne" column="nomPersonne" />
    <property name="prenomPersonne" column="prenomPersonne" />
    <property name="telephonePersonne" column="telephonePersonne" />
    <property name="emailPersonne" column="emailPersonne" />
    <one-to-one name="detailPersonne" class="bean.DetailPersonne" cascade="save-update" />
    </class>
    </hibernate-mapping>
    Fichier DetailPersonne.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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
     
    <hibernate-mapping>
    <class name="bean.DetailPersonne" table="TDetailPersonne">
    <id name="idPersonne" column="idPersonne">
    <generator class="foreign">
    <param name="property">personne</param>
    </generator>
    </id>
    <property name="situationMatrimoniale" column="situationMatrimoniale" />
    <property name="nomprenomConjoint" column="nomprenomConjoint" />
    <property name="nombreEnfant" column="nombreEnfant" />
    <one-to-one name="personne" class="bean.Personne" constrained="true" />
    </class>
    </hibernate-mapping>

    Fichier HibernateUtil:

    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 util;
     
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;
     
    public class HibernateUtil {
     
    	public static final SessionFactory sf;
     
    	static{
    		try{
    			sf = new Configuration().configure().buildSessionFactory();
    		}catch(Throwable e){
    			System.err.println("Echec creation session factory "+e);
    			throw new ExceptionInInitializerError(e);
    		}
    	}
     
    	public static SessionFactory getSessionFactory(){
    		return sf;
    	}
     
    }

    Fichier PersonneManager.java

    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 manager;
     
    import bean.Personne;
    import bean.DetailPersonne;
    import util.HibernateUtil;
    import org.hibernate.Session;
     
    public class PersonneManager {
     
    	public void ajouterPersonne(String nomPersonne, String prenomPersonne,
    			String telephonePersonne, String emailPersonne, DetailPersonne detailPersonne){
    		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    		session.beginTransaction();
    		Personne p = new Personne();
    		p.setNomPersonne(prenomPersonne);
    		p.setPrenomPersonne(prenomPersonne);
    		p.setTelephonePersonne(telephonePersonne);
    		p.setEmailPersonne(emailPersonne);
    		p.setDetailPersonne(detailPersonne);
    		session.save(p);
    		session.getTransaction().commit();		
    	}
    }

    Fichier Main.java

    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
     
    package test;
     
    import util.HibernateUtil;
    import bean.DetailPersonne;
    import manager.PersonneManager;
     
    public class Main {
     
    	/**
             * @param args
             */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		DetailPersonne dpm = new DetailPersonne(2, "Marié", "FASSINOU M. Rose");
    		PersonneManager pm = new PersonneManager();
    		pm.ajouterPersonne("LAKATAN", "Adebayo G. Wilfried", "00229 97 85 87 11", "lakatan_wilfried@hotmail.fr",dpm);
    		HibernateUtil.sf.close();
    	}
     
    }
    Je ne trouve pas où est l'erreur...
    Merci pour l'aide

  2. #2
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Bonjour,

    Caused by: org.hibernate.PropertyNotFoundException: field [situationMatrimoniale] not found on bean.DetailPersonne
    Soit tu n'as pas l'attribut situationMatrimoniale dans la classe DetailPersonne, soit il te manque le getter et setter.

    A+.

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2014
    Messages
    29
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Bénin

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 29
    Points : 31
    Points
    31
    Par défaut Attribut situationMatrimoniale présent dans la classe
    Citation Envoyé par andry.aime Voir le message
    Bonjour,


    Soit tu n'as pas l'attribut situationMatrimoniale dans la classe DetailPersonne, soit il te manque le getter et setter.

    A+.
    Si si j'ai l'attribut situationMatrimoniale dans la classe DetailPersonne, pareil pour les getter et setter

    Fichier DetailPersonne.java

    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
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    package bean;
     
    public class DetailPersonne {
     
    	private int idPersonne, nombreEnfant;
    	private String situationMatrimonial, nomprenomConjoint; 
    	private Personne personne;
     
    	public DetailPersonne(){
     
    	}
     
    	public DetailPersonne(int nombreEnfant, String situationMatrimonial, String nomprenomConjoint) {
    		super();
    		this.nombreEnfant = nombreEnfant;
    		this.situationMatrimonial = situationMatrimonial;
    		this.nomprenomConjoint = nomprenomConjoint;
    	}
     
    	public int getIdPersonne() {
    		return idPersonne;
    	}
     
    	public void setIdPersonne(int idPersonne) {
    		this.idPersonne = idPersonne;
    	}
     
    	public int getNombreEnfant() {
    		return nombreEnfant;
    	}
     
    	public void setNombreEnfant(int nombreEnfant) {
    		this.nombreEnfant = nombreEnfant;
    	}
     
    	public String getSituationMatrimonial() {
    		return situationMatrimonial;
    	}
     
    	public void setSituationMatrimonial(String situationMatrimonial) {
    		this.situationMatrimonial = situationMatrimonial;
    	}
     
    	public String getNomprenomConjoint() {
    		return nomprenomConjoint;
    	}
     
    	public void setNomprenomConjoint(String nomprenomConjoint) {
    		this.nomprenomConjoint = nomprenomConjoint;
    	}
     
    	public Personne getPersonne() {
    		return personne;
    	}
     
    	public void setPersonne(Personne personne) {
    		this.personne = personne;
    	}
     
    	@Override
    	public String toString() {
    		return "DetailPersonne [idPersonne=" + idPersonne + ", nombreEnfant="
    				+ nombreEnfant + ", situationMatrimonial="
    				+ situationMatrimonial + ", nomprenomConjoint="
    				+ nomprenomConjoint + ", personne=" + personne + "]";
    	}
     
    }

    Fichier Personne.java

    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
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    package bean;
     
    public class Personne {
     
    	private int idPersonne;
    	private String nomPersonne, prenomPersonne, telephonePersonne, emailPersonne;
    	private DetailPersonne detailPersonne;
     
    	public Personne(){
     
    	}
     
    	public Personne(String nomPersonne, String prenomPersonne,
    			String telephonePersonne, String emailPersonne,
    			DetailPersonne detailPersonne) {
    		super();
    		this.nomPersonne = nomPersonne;
    		this.prenomPersonne = prenomPersonne;
    		this.telephonePersonne = telephonePersonne;
    		this.emailPersonne = emailPersonne;
    		this.detailPersonne = detailPersonne;
    	}
     
    	public int getIdPersonne() {
    		return idPersonne;
    	}
     
    	public void setIdPersonne(int idPersonne) {
    		this.idPersonne = idPersonne;
    	}
     
    	public String getNomPersonne() {
    		return nomPersonne;
    	}
     
    	public void setNomPersonne(String nomPersonne) {
    		this.nomPersonne = nomPersonne;
    	}
     
    	public String getPrenomPersonne() {
    		return prenomPersonne;
    	}
     
    	public void setPrenomPersonne(String prenomPersonne) {
    		this.prenomPersonne = prenomPersonne;
    	}
     
    	public String getTelephonePersonne() {
    		return telephonePersonne;
    	}
     
    	public void setTelephonePersonne(String telephonePersonne) {
    		this.telephonePersonne = telephonePersonne;
    	}
     
    	public String getEmailPersonne() {
    		return emailPersonne;
    	}
     
    	public void setEmailPersonne(String emailPersonne) {
    		this.emailPersonne = emailPersonne;
    	}
     
    	public DetailPersonne getDetailPersonne() {
    		return detailPersonne;
    	}
     
    	public void setDetailPersonne(DetailPersonne detailPersonne) {
    		this.detailPersonne = detailPersonne;
    	}
     
    	@Override
    	public String toString() {
    		return "Personne [idPersonne=" + idPersonne + ", nomPersonne="
    				+ nomPersonne + ", prenomPersonne=" + prenomPersonne
    				+ ", telephonePersonne=" + telephonePersonne
    				+ ", emailPersonne=" + emailPersonne + "]";
    	}	
     
    }

  4. #4
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Je dis que non

    Citation Envoyé par xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <property name="situationMatrimoniale" column="situationMatrimoniale" />
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    public void setSituationMatrimonial(String situationMatrimonial) {
    		this.situationMatrimonial = situationMatrimonial;
    	}
    il te manque un "e" dans la classe java


  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2014
    Messages
    29
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Bénin

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 29
    Points : 31
    Points
    31
    Par défaut Erreur vérifiée et corrigée
    Citation Envoyé par andry.aime Voir le message
    Je dis que non



    il te manque un "e" dans la classe java

    Merci pour le coup de main.

    L'erreur a été corrigée et voici maintenant le message d'erreur que j'ai:

    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
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    15 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
    15 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
    31 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
    31 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
    109 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
    109 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
    218 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : bean/Personne.hbm.xml
    328 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: bean.Personne -> TPersonne
    359 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : bean/DetailPersonne.hbm.xml
    390 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: bean.DetailPersonne -> TDetailPersonne
    453 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
    468 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
    468 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 1
    468 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
    468 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/bd_personne
    468 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=root, password=****}
    952 [main] INFO org.hibernate.cfg.SettingsFactory - RDBMS: MySQL, version: 5.6.15-log
    952 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.23 ( Revision: ${bzr.revision-id} )
    997 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
    997 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
    997 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    997 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
    997 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
    997 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
    997 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
    997 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
    997 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
    997 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
    997 [main] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
    997 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
    997 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
    997 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
    997 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
    997 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    1013 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
    1013 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
    1013 [main] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
    1013 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
    1013 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
    1013 [main] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
    1013 [main] INFO org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge - Cache provider: org.hibernate.cache.NoCacheProvider
    1013 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
    1013 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
    1028 [main] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
    1028 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
    1028 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
    1028 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
    1028 [main] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
    1091 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
    1294 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
    1310 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - Running hbm2ddl schema export
    1310 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - exporting generated schema to database
    1601 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - schema export complete
    Hibernate: select max(idPersonne) from TPersonne
    Exception in thread "main" org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property: personne
    	at org.hibernate.id.ForeignGenerator.generate(ForeignGenerator.java:68)
    	at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:122)
    	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
    	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
    	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
    	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
    	at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:535)
    	at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:527)
    	at org.hibernate.engine.CascadingAction$5.cascade(CascadingAction.java:241)
    	at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:292)
    	at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:240)
    	at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:193)
    	at org.hibernate.engine.Cascade.cascade(Cascade.java:154)
    	at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:479)
    	at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:357)
    	at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
    	at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:144)
    	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
    	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
    	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
    	at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
    	at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:535)
    	at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:527)
    	at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:523)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:342)
    	at com.sun.proxy.$Proxy0.saveOrUpdate(Unknown Source)
    	at manager.PersonneManager.ajouterPersonne(PersonneManager.java:20)
    	at test.Main.main(Main.java:16)

    Je n'ai aucune idée de ce qui pourrait en être la cause. Je vous prie de bien vouloir m'aider à l'identifier.

    Merci pour l'aide.

    Adebayo

  6. #6
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    p.setDetailPersonne(detailPersonne);
    		session.save(p);
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    p.setDetailPersonne(detailPersonne);
    detailPersonne.setPersonne(p);
    		session.save(p);
    Et fait attention avec l'utilisation de <generator class="increment" /> :
    http://docs.jboss.org/hibernate/orm/...declaration-id

    increment

    generates identifiers of type long, short or int that are unique only when no other process is inserting data into the same table. Do not use in a cluster.
    A+.

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

Discussions similaires

  1. [TSocket] Message d'erreur
    Par rgz dans le forum Web & réseau
    Réponses: 6
    Dernier message: 04/07/2003, 09h16
  2. Surcharger le message d'erreur après un OnException
    Par Tirlibibi dans le forum XMLRAD
    Réponses: 2
    Dernier message: 24/04/2003, 11h42
  3. Réponses: 4
    Dernier message: 04/03/2003, 01h05
  4. [CR] Message d'erreur
    Par nono1 dans le forum SAP Crystal Reports
    Réponses: 2
    Dernier message: 11/09/2002, 14h54
  5. Réponses: 2
    Dernier message: 27/05/2002, 19h46

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