Bonjour tout le monde,
je travaille sur un projet j2ee avec hibernate et postgre comme sgdb, en fait j'ai un problème : lorsque je teste le mapping d'une classe Agence il me sort l'erreur suivante:
voila les codes sources :ERROR: relation "agence" does not exist
agence.hbm:
BaseAgence.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 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > <hibernate-mapping package="com.pfe.hibernate"> <class name="Agence" table="Agence"> <id column="Id" name="Id" type="java.lang.Long" > <generator class="increment" /> </id> <property column="Libelle" name="Libelle" not-null="false" type="string" /> </class> </hibernate-mapping>
agence.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
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 package com.pfe.hibernate.base; import java.io.Serializable; /** * This class has been automatically generated by Hibernate Synchronizer. * For more information or documentation, visit The Hibernate Synchronizer page * at http://www.binamics.com/hibernatesync or contact Joe Hudson at joe@binamics.com. * * This is an object that contains data related to the Agence table. * Do not modify this class because it will be overwritten if the configuration file * related to this class is modified. * * @hibernate.class * table="Agence" */ public abstract class BaseAgence implements Serializable { public static String PROP_LIBELLE = "Libelle"; public static String PROP_ID = "Id"; private int hashCode = Integer.MIN_VALUE; // primary key private java.lang.Long _id; // fields private java.lang.String _libelle; // constructors public BaseAgence () { initialize(); } /** * Constructor for primary key */ public BaseAgence (java.lang.Long _id) { this.setId(_id); initialize(); } protected void initialize () {} /** * Return the unique identifier of this class * @hibernate.id * generator-class="increment" * column="Id" */ public java.lang.Long getId () { return _id; } /** * Set the unique identifier of this class * @param _id the new ID */ public void setId (java.lang.Long _id) { this._id = _id; this.hashCode = Integer.MIN_VALUE; } /** * Return the value associated with the column: Libelle */ public java.lang.String getLibelle () { return _libelle; } /** * Set the value related to the column: Libelle * @param _libelle the Libelle value */ public void setLibelle (java.lang.String _libelle) { this._libelle = _libelle; } public boolean equals (Object obj) { if (null == obj) return false; if (!(obj instanceof com.pfe.hibernate.base.BaseAgence)) return false; else { com.pfe.hibernate.base.BaseAgence mObj = (com.pfe.hibernate.base.BaseAgence) obj; if (null == this.getId() || null == mObj.getId()) return false; else return (this.getId().equals(mObj.getId())); } } public int hashCode () { if (Integer.MIN_VALUE == this.hashCode) { if (null == this.getId()) return super.hashCode(); else { String hashStr = this.getClass().getName() + ":" + this.getId().hashCode(); this.hashCode = hashStr.hashCode(); } } return this.hashCode; } public String toString () { return super.toString(); } }
TestHibernate.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 package com.pfe.hibernate; import com.pfe.hibernate.base.BaseAgence; /** * This is the object class that relates to the Agence table. * Any customizations belong here. */ public class Agence extends BaseAgence { /*[CONSTRUCTOR MARKER BEGIN]*/ public Agence () { super(); } /** * Constructor for primary key */ public Agence (java.lang.Long _id) { super(_id); } /*[CONSTRUCTOR MARKER END]*/ }
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 package com.pfe.exemple; import com.pfe.hibernate.Agence; import com.pfe.hibernate.Utilisateur; import com.pfe.hibernate.util.HibernateUtil; import net.sf.hibernate.HibernateException; import net.sf.hibernate.Session; import net.sf.hibernate.SessionFactory; import net.sf.hibernate.Transaction; public class TestHibernate { /** * @param args */ public static void main(String[] args) throws HibernateException{ Session s = HibernateUtil.currentSession(); Transaction t = s.beginTransaction(); Agence ag = new Agence(); ag.setLibelle("test"); s.save(ag); t.commit(); s.close(); } }
Partager