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 :
voici la class ClientDaoImpllog4j: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 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 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); } }
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 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 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
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; }
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
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; }
Quelqu'un saurait-il m'indiquer d'où peut venir le problème ?
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>
Merci d'avance pour votre aide.
Partager