Bonjour je débute en Hibernate et je n'arrive pas à mapper correctement ma classe CompteUtilisateur ci-dessous; j'ai l'erreur suivante : java.lang.IllegalArgumentException: Object: fr.aef.util.CompteUtilisateur@163e2ff is not a known entity type.
Voici le code de ma classe :
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package fr.aef.util; import java.io.Serializable; import java.util.GregorianCalendar; import javax.persistence.Column; import javax.persistence.Embedded; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.Table; /** * * @author ratatouille */ @Entity @Table(name="UTILISATEURS") @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) public class CompteUtilisateur implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "ID") private Long id; @Column(name="NOM") private String nom; @Column(name="PRENOM") private String prenom; @Column(name="EMAIL") private String email; // @Column(name="DATE_DE_NAISSANCE") //private GregorianCalendar dateDeNaissance; /*@Embedded private Adresse adresse; @Embedded private Telephone telephone; */ public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } /*public void setAdresse(Adresse adresse) { this.adresse = adresse; }*/ public void setDateDeNaissance(GregorianCalendar dateDeNaissance) { //this.dateDeNaissance = dateDeNaissance; } public void setNom(String nom) { if( nom == null ) throw new IllegalArgumentException(); this.nom = nom; } public void setPrenom(String prenom) { if( prenom == null) throw new IllegalArgumentException(); this.prenom = prenom; } /*public void setTelephone(Telephone telephone) { this.telephone = telephone; } public Adresse getAdresse() { return adresse; }*/ /* public GregorianCalendar getDateDeNaissance() { return dateDeNaissance; } */ public String getNom() { return nom; } public String getPrenom() { return prenom; } /*public Telephone getTelephone() { return telephone; }*/ public Long getId() { return id; } public void setId(Long id) { this.id = id; } public CompteUtilisateur(String nom, String prenom) { if( nom == null || prenom == null ) throw new IllegalArgumentException(); this.nom = nom; this.prenom = prenom; } public CompteUtilisateur() { } }
Le code pour mettre l'entité dans la base :
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 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package fr.aef.services; import fr.aef.util.CompteUtilisateur; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityTransaction; import javax.persistence.Persistence; /** * * @author ratatouille */ public class CompteManager { public CompteManager() { } public void creerUnCompte( CompteUtilisateur compte ) { if( compte == null ) throw new IllegalArgumentException(); EntityManagerFactory emf; EntityManager em; EntityTransaction tx; emf = Persistence.createEntityManagerFactory("AnnuaireEntrepreneursPU"); em = emf.createEntityManager(); tx = em.getTransaction(); try { tx.begin(); em.persist(compte);//exception intervient ici ! tx.commit(); } catch(Exception e ) { System.out.println( e.toString() ); } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } } }
Le fichier persistence.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 <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="AnnuaireEntrepreneursPU" transaction-type="JTA"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>AnnuaireEntrepreneursDB</jta-data-source> <class>fr.aef.util.CompteUtilisateur</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> <properties> <property name="hibernate.show_sql" value="false"/> <property name="hibernate.format_sql" value="false"/> <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/> <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:mem:aname"/> <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/> <property name="hibernate.hbm2ddl.auto" value="update"/> </properties> </persistence-unit> </persistence>
Est ce que quelqu'un aurait une idée svp ??
Merci
Partager