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 d'insertion


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
    Novembre 2005
    Messages
    136
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 136
    Par défaut Problème d'insertion
    Bonjour,

    Je développe une application et j'ai un problème avec une insertion one-to-one, j'obtiens le message d'erreur suivant :
    log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
    log4j:WARN Please initialize the log4j system properly.
    erreur add client v : org.hibernate.exception.GenericJDBCException: could not insert: [com.livre.beans.Client]
    voici la class ClientDaoImpl
    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
    package com.livre.dao.impl;
     
    import java.util.ArrayList;
     
    import org.hibernate.HibernateException;
    import org.hibernate.Query;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.Transaction;
    import com.livre.beans.Client;
    import com.livre.dao.interfaces.Iclient;
    import com.livre.utile.Hiber;
     
    @SuppressWarnings("unchecked")
    public class ClientDaoImpl implements Iclient {
        private Transaction tx =null;
     
        public ClientDaoImpl() {
     
        }
     
        @Override
        public void add(Client o) {
            try{
                Session session =Hiber.getSessionFactory().openSession();
                tx=session.beginTransaction();
                session.save(o);
                tx.commit();
            }catch (Exception e) {System.out.println("erreur add client v : " +e);
     
            }
        }
    Voici la classe ClientManagerImpl
    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
    public class ClientManagerImpl implements IclientManager<Client> {
     
        private Dao<Client> client =null;
        private Dao<Adresse> adresse =null;
     
        public Dao<Client> getClient() {
            if(client==null)
                client = new ClientDaoImpl();
            return client;
        }
     
        public void setClient(Dao<Client> client) {
            this.client = client;
        }
     
        public Dao<Adresse> getAdresse() {
            if(adresse==null)
                adresse = new AdresseDaoImpl();
            return adresse;
        }
     
        public void setAdresse(Dao<Adresse> adresse) {
            this.adresse = adresse;
        }
     
     
        public ClientManagerImpl() {
     
        }
     
        @Override
        public ArrayList<Client> ClientfindAllManager() {
            return this.getClient().findAll();
        }
     
        @Override
        public boolean PwdOublieManage(Client O) {
            return this.PwdOublieManage(O);
        }
     
        @Override
        public boolean ValideLoginManage(Client o) {
            return this.ValideLoginManage(o);
        }
     
        @Override
        public void addClientManager(Client o) {
            try{
                this.getAdresse().add(o.getAdresse());        
                this.getClient().add(o);
            }catch (Exception e) {System.out.print("add manager client :" +e.getMessage());}
        }
    Classe client beans
    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
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    import java.util.HashSet;
    import java.util.Set;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.GeneratedValue;
    import static javax.persistence.GenerationType.IDENTITY;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    import javax.persistence.UniqueConstraint;
     
    /**
     * Client generated by hbm2java
     */
    @Entity
    @Table(name = "client", catalog = "bdlivre", uniqueConstraints = @UniqueConstraint(columnNames = "login"))
    public class Client implements java.io.Serializable {
     
        private Integer idclient;
        private Adresse adresse;
        private String login;
        private String passwd;
        private String nom;
        private String prenom;
        private Set<Commande> commandes = new HashSet<Commande>(0);
     
        public Client() {
        }
     
        public Client(Adresse adresse, String login, String passwd, String nom) {
            this.adresse = adresse;
            this.login = login;
            this.passwd = passwd;
            this.nom = nom;
        }
     
        public Client(Adresse adresse, String login, String passwd, String nom,
                String prenom, Set<Commande> commandes) {
            this.adresse = adresse;
            this.login = login;
            this.passwd = passwd;
            this.nom = nom;
            this.prenom = prenom;
            this.commandes = commandes;
        }
     
        @Id
        @GeneratedValue(strategy = IDENTITY)
        @Column(name = "idclient", unique = true, nullable = false)
        public Integer getIdclient() {
            return this.idclient;
        }
     
        public void setIdclient(Integer idclient) {
            this.idclient = idclient;
        }
     
        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "Idadresse", nullable = false)
        public Adresse getAdresse() {
            return this.adresse;
        }
     
        public void setAdresse(Adresse adresse) {
            this.adresse = adresse;
        }
     
        @Column(name = "login", unique = true, nullable = false, length = 10)
        public String getLogin() {
            return this.login;
        }
     
        public void setLogin(String login) {
            this.login = login;
        }
     
        @Column(name = "passwd", nullable = false, length = 10)
        public String getPasswd() {
            return this.passwd;
        }
     
        public void setPasswd(String passwd) {
            this.passwd = passwd;
        }
     
        @Column(name = "nom", nullable = false, length = 20)
        public String getNom() {
            return this.nom;
        }
     
        public void setNom(String nom) {
            this.nom = nom;
        }
     
        @Column(name = "prenom", length = 15)
        public String getPrenom() {
            return this.prenom;
        }
     
        public void setPrenom(String prenom) {
            this.prenom = prenom;
        }
    Classe Adresse
    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
    package com.livre.beans;
     
    // Generated 31-juil.-2012 9:19:33 by Hibernate Tools 3.3.0.GA
     
    import java.util.HashSet;
    import java.util.Set;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.GeneratedValue;
    import static javax.persistence.GenerationType.IDENTITY;
    import javax.persistence.Id;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
     
    /**
     * Adresse generated by hbm2java
     */
    @Entity
    @Table(name = "adresse", catalog = "bdlivre")
    public class Adresse implements java.io.Serializable {
     
        private Integer idadresse;
        private String ville;
        private String adresse;
        private String email;
        private String code;
        private Set<Client> clients = new HashSet<Client>(0);
     
        public Adresse() {
        }
     
        public Adresse(String ville, String adresse, String email, String code,
                Set<Client> clients) {
            this.ville = ville;
            this.adresse = adresse;
            this.email = email;
            this.code = code;
            this.clients = clients;
        }
     
        @Id
        @GeneratedValue(strategy = IDENTITY)
        @Column(name = "Idadresse", unique = true, nullable = false)
        public Integer getIdadresse() {
            return this.idadresse;
        }
     
        public void setIdadresse(Integer idadresse) {
            this.idadresse = idadresse;
        }
     
        @Column(name = "ville", length = 30)
        public String getVille() {
            return this.ville;
        }
     
        public void setVille(String ville) {
            this.ville = ville;
        }
     
        @Column(name = "adresse", length = 30)
        public String getAdresse() {
            return this.adresse;
        }
    Fichier XML 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
    <?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.bytecode.use_reflection_optimizer">false</property>
            <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
            <property name="hibernate.connection.password">root</property>
            <property name="hibernate.connection.url">jdbc:mysql://localhost/bdlivre</property>
            <property name="hibernate.connection.username">root</property>
            <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
            <property name="hibernate.search.autoregister_listeners">false</property>
            <mapping class="com.livre.beans.Livre" />
            <mapping class="com.livre.beans.Client" />
            <mapping class="com.livre.beans.Commande" />
            <mapping class="com.livre.beans.Cmdlivre" />
            <mapping class="com.livre.beans.Adresse" />
            <mapping class="com.livre.beans.Auteur" />
            <mapping class="com.livre.beans.Theme" />
            <mapping class="com.livre.beans.Ouvrage" />
        </session-factory>
    </hibernate-configuration>
    Quelqu'un saurait-il m'indiquer d'où peut venir le problème ?

    Merci d'avance pour votre aide.

  2. #2
    Membre chevronné
    Homme Profil pro
    Ed Nat
    Inscrit en
    Janvier 2013
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Ed Nat
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2013
    Messages : 325
    Par défaut
    Bonjour,
    ce code là ne donne pas grand chose...
    Il manque la trace complète de l'exception, le code du bean Client, son mapping, la structure des données correspondante

  3. #3
    Membre du Club
    Homme Profil pro
    Inscrit en
    Février 2013
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations forums :
    Inscription : Février 2013
    Messages : 7
    Par défaut
    il faut ajouter dans la partie mapping du fichier config.xml les differents packages ...

Discussions similaires

  1. problème d'insertion de données
    Par Falgan dans le forum ASP
    Réponses: 2
    Dernier message: 06/04/2004, 09h29
  2. Probléme d'insertion par défault
    Par xavier62 dans le forum SQL
    Réponses: 7
    Dernier message: 28/11/2003, 13h03
  3. [Interbase 7] Problème d'insertion de données
    Par Tuscelan dans le forum InterBase
    Réponses: 12
    Dernier message: 19/11/2003, 22h58
  4. STL : std::set problème avec insert ...
    Par Big K. dans le forum MFC
    Réponses: 13
    Dernier message: 08/11/2003, 01h02
  5. Problème d'insertion avec MySQL
    Par Sonny dans le forum ASP
    Réponses: 13
    Dernier message: 28/08/2003, 13h52

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