Bonjour, j'utilise pas spring et j'ai lerreur suivante
Voila mon fichier de mapping
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 Exception in thread "main" ERROR - could not initialize proxy - the owning Session was closed org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84) at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134) at fr.planning.pojo.Collaborateur$$EnhancerByCGLIB$$d9c24562.getNom(<generated>) at fr.planning.pojo.dao.ProfilDAO.main(ProfilDAO.java:39) org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84) at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134) at fr.planning.pojo.Collaborateur$$EnhancerByCGLIB$$d9c24562.getNom(<generated>) at fr.planning.pojo.dao.ProfilDAO.main(ProfilDAO.java:39)
voila mon code qui pose probleme :
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
129
130
131
132
133
134
135
136
137
138
139
140
141 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <hibernate-mapping package="fr.planning.pojo"> <class name="Profil" table="PROFIL" > <id name="id" type="integer" column="PRO_ID" > <generator class="native"/> </id> <property name="dateDispo" column="PRO_DATE_DISPO" type="date" not-null="false" length="10" /> <property name="droit" column="PRO_DROIT" type="integer" not-null="false" length="11" /> <property name="type_utilisateur" column="PRO_UTILISATEUR" type="java.lang.Boolean" not-null="false" length="1" /> <property name="commercial" column="PRO_COMMERCIAL" type="java.lang.Boolean" not-null="false" length="1" /> <property name="reserver" column="PRO_RESERVER" type="java.lang.Boolean" not-null="false" length="1" /> <property name="siege" column="PRO_SIEGE" type="java.lang.Boolean" not-null="false" length="1" /> <property name="mobilite" column="PRO_MOBILITE" type="java.lang.Boolean" not-null="false" length="1" /> <many-to-one name="situation" column="SIT_ID" class="Situation" not-null="false" > </many-to-one> <many-to-one name="client" column="CLT_ID" class="Client" not-null="false" > </many-to-one> <many-to-one name="societe" column="SOC_ID" class="Societe" not-null="false" > </many-to-one> <many-to-one name="fonction" column="RFN_ID" class="Fonction" not-null="false" > </many-to-one> <many-to-one name="collaborateur" column="COL_ID" class="Collaborateur" not-null="false" > </many-to-one> <many-to-one name="statut" column="STT_ID" class="Statut" not-null="false" > </many-to-one> <many-to-one name="utilisateur" column="UTL_ID" class="Utilisateur" not-null="false" > </many-to-one> <set name="entites" table="PREFERENCE" cascade="all" > <key column="PRO_ID"/> <many-to-many column="RTT_ID" class="Entite"/> </set> <set name="utilisateurs" table="RESERVATION" cascade="all" > <key column="PRO_ID"/> <many-to-many column="UTL_ID" class="Utilisateur"/> </set> </class> </hibernate-mapping>
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 public class ProfilDAO extends BaseProfilDAO { /** * Default constructor. Can be used in place of getInstance() */ public ProfilDAO () {} public Profil getByCollaborateurId(Integer id, Session session){ ProfilDAO.initialize(); Profil profil = (Profil)ProfilDAO.getInstance().getQuery("from Profil profil fetch all properties where profil.collaborateur.id =:id",session).setInteger("id",id).uniqueResult(); //Profil profil = (Profil)ProfilDAO.getInstance().getQuery("from Profil profil inner join fetch profil.collaborateur where profil.collaborateur.id =:id",session).setInteger("id",id).uniqueResult(); return profil; } public static void main(String[] args){ Session session = HibernateUtil.currentSession(); Transaction tx = session.beginTransaction(); Profil profil = ProfilDAO.getInstance().getByCollaborateurId(Integer.valueOf(24),session); tx.commit(); session.close(); System.out.println(profil.toString()); System.out.println(profil.getCollaborateur().getNom()); } }
Partager