hey,
I'm student in internship and i tryed to use hibernate for the first time!
I've read a lot of website but i don't find a solution to my problem :s.
I'm using hibernate 3 and mysql 5.5. I also use GWT and gilead but i don't think that problems are here!
I've got 2 class wgarticles and wgfamilles whith this mapping :
Code:
<hibernate-mapping package="winGsmGWT.domain">
<class name="Wgarticles" table="wgarticles" catalog="wingsm">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="identity" />
</id>
<many-to-one name="wgfournisseurs" class="Wgfournisseurs" fetch="select">
<column name="IDFournisseur" />
</many-to-one>
<many-to-one name="wgfamilles" class="Wgfamilles" fetch="select">
<column name="IDFamille" />
</many-to-one>
<many-to-one name="wgtva" class="Wgtva" fetch="select">
<column name="IDTva" />
</many-to-one>
<many-to-one name="wgmarques" class="Wgmarques" fetch="select">
<column name="IDMarque" />
</many-to-one>
<property name="SDesignation" type="string">
<column name="S_Designation" length="45" />
</property>
<property name="RPrixAchat" type="java.lang.Long">
<column name="R_PrixAchat" precision="10" scale="0" />
</property>
<property name="RAchatMois" type="float">
<column name="R_AchatMois" precision="45" scale="0" />
</property>
<property name="RAchatCumule" type="float">
<column name="R_AchatCumule" precision="45" scale="0" />
</property>
<property name="RPrixRevient" type="float">
<column name="R_PrixRevient" precision="45" scale="0" />
</property>
<property name="RPrixUnitaire" type="float">
<column name="R_PrixUnitaire" precision="45" scale="0" />
</property>
<property name="RQteVendue" type="float">
<column name="R_QteVendue" precision="45" scale="0" />
</property>
<property name="RQteVendueCumule" type="float">
<column name="R_QteVendueCumule" precision="45" scale="0" />
</property>
<property name="RChiffreAffaireMois" type="float">
<column name="R_ChiffreAffaireMois" precision="45" scale="0" />
</property>
<property name="RChiffreAffaireCumule" type="float">
<column name="R_ChiffreAffaireCumule" precision="45" scale="0" />
</property>
<property name="RMarge" type="float">
<column name="R_Marge" precision="25" scale="0" />
</property>
<property name="RMargeCumule" type="float">
<column name="R_MargeCumule" precision="25" scale="0" />
</property>
<property name="SObservation" type="string">
<column name="S_Observation" length="65535" />
</property>
<property name="RPrixTtc" type="float">
<column name="R_PrixTTC" precision="45" scale="0" />
</property>
<property name="SGencode" type="string">
<column name="S_Gencode" length="45" />
</property>
<set name="wgarticlesavecimeis" inverse="true">
<key>
<column name="IDArticle" not-null="true" />
</key>
<one-to-many class="Wgarticlesavecimei" />
</set>
<set name="wgfacturesarticleses" inverse="true">
<key>
<column name="IDArticle" />
</key>
<one-to-many class="Wgfacturesarticles" />
</set>
<set name="wgticketsarticlesSaves" inverse="true">
<key>
<column name="IDArticle" />
</key>
<one-to-many class="WgticketsarticlesSave" />
</set>
<set name="wgticketsarticleses" inverse="true">
<key>
<column name="IDArticle" />
</key>
<one-to-many class="Wgticketsarticles" />
</set>
<set name="wgcommandearticles" inverse="true">
<key>
<column name="IDArticle" not-null="true" />
</key>
<one-to-many class="Wgcommandearticle" />
</set>
<set name="wgfacturesarticlesSaves" inverse="true">
<key>
<column name="IDArticle" />
</key>
<one-to-many class="WgfacturesarticlesSave" />
</set>
<set name="wgbonslivraisonsarticleses" inverse="true">
<key>
<column name="IDArticle" />
</key>
<one-to-many class="Wgbonslivraisonsarticles" />
</set>
<set name="wgbonslivraisonsarticlesSaves" inverse="true">
<key>
<column name="IDArticle" />
</key>
<one-to-many class="WgbonslivraisonsarticlesSave" />
</set>
<set name="wgstockses" inverse="true">
<key>
<column name="IDArticle" />
</key>
<one-to-many class="Wgstocks" />
</set>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping package="winGsmGWT.domain">
<class name="Wgfamilles" table="wgfamilles" catalog="wingsm">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="identity" />
</id>
<many-to-one name="wgfamilles" class="Wgfamilles" fetch="select">
<column name="IDFamille">
<comment>l'identifiant de la famille "mÇùre" si c'est une sous famille</comment>
</column>
</many-to-one>
<property name="SNom" type="string">
<column name="S_Nom" length="45" />
</property>
<set name="wgfamilleses" inverse="true">
<key>
<column name="IDFamille">
<comment>l'identifiant de la famille "mÇùre" si c'est une sous famille</comment>
</column>
</key>
<one-to-many class="Wgfamilles" />
</set>
<set name="wgarticleses" inverse="true">
<key>
<column name="IDFamille" />
</key>
<one-to-many class="Wgarticles" />
</set>
</class>
</hibernate-mapping>
I use a class wgarticleManager to make my opération on the pojo :
Code:
public static ArrayList<Wgarticles> getListeArticles(Session s,Wgfournisseurs fournisseur, Wgfamilles famille){
ArrayList<Wgarticles> ret = new ArrayList<Wgarticles>();
String motCle="";
try {
String query;
if(fournisseur==null && famille==null){
query="from Wgarticles a inner join fetch a.wgfamilles inner join fetch a.wgmarques";
}
else{
query="from Wgarticles a inner join fetch a.wgfamilles inner join fetch a.wgmarques inner join fetch a.wgfournisseurs where ";
if(fournisseur!=null){
System.out.println("session : "+s);
query.concat("wgfournisseurs="+fournisseur);
motCle=" and ";
}
if(famille!=null){
System.out.println("session2 : "+s);
query.concat(motCle+"wgfamilles="+famille);
}
}
ret = (ArrayList<Wgarticles>)s.createQuery(query).list();
Hibernate.initialize(ret);
} catch (HibernateException e) {
e.printStackTrace();
}
System.out.println("ret : "+ret);
return ret;
}
and here the servlet :
Code:
public ArrayList<Wgarticles> listeArticles(Wgfournisseurs fournisseur, Wgfamilles famille) {
System.out.println("testServiceImpl.listeArticle");
System.out.println("famille : "+famille);
ArrayList<Wgarticles> ret;
Session s = persistenceUtil.getSessionFactory().getCurrentSession();
if (fournisseur != null)
fournisseur=(Wgfournisseurs)s.get(Wgfournisseurs.class, fournisseur.getId());
if (famille!=null)
famille=(Wgfamilles)s.get(Wgfamilles.class, famille.getId());
System.out.println("fournisseur : "+fournisseur);
System.out.println("session : "+s.hashCode());
ret=WgarticlesManager.getListeArticles(s, fournisseur, famille);
persistenceUtil.closeCurrentSession();
return ret;
}
when i launch the program i've got this exception :
Code:
14:40:33,015 DEBUG SQL:111 - select wgcommande0_.IDArticle as IDArticle1_, wgcommande0_.ID as ID1_, wgcommande0_.ID as ID25_0_, wgcommande0_.IDCommande as IDCommande25_0_, wgcommande0_.IDArticle as IDArticle25_0_, wgcommande0_.I_Quantite as I4_25_0_ from wingsm.wgcommandearticle wgcommande0_ where wgcommande0_.IDArticle=?
14:40:33,031 DEBUG SQL:111 - select wgfactures0_.IDArticle as IDArticle1_, wgfactures0_.ID as ID1_, wgfactures0_.ID as ID8_0_, wgfactures0_.IDTva as IDTva8_0_, wgfactures0_.IDArticle as IDArticle8_0_, wgfactures0_.IDFacture as IDFacture8_0_, wgfactures0_.R_PrixUnitaire as R5_8_0_, wgfactures0_.I_Quantite as I6_8_0_ from wingsm.wgfacturesarticles_save wgfactures0_ where wgfactures0_.IDArticle=?
14:40:33,031 DEBUG SQL:111 - select wgfactures0_.IDArticle as IDArticle1_, wgfactures0_.ID as ID1_, wgfactures0_.ID as ID19_0_, wgfactures0_.IDTva as IDTva19_0_, wgfactures0_.IDArticle as IDArticle19_0_, wgfactures0_.IDFacture as IDFacture19_0_, wgfactures0_.R_PrixUnitaire as R5_19_0_, wgfactures0_.I_Quantite as I6_19_0_ from wingsm.wgfacturesarticles wgfactures0_ where wgfactures0_.IDArticle=?
hashcode de wgfamilllllllllllllllllllllllllles111 : 296209368
14:40:33,031 DEBUG SQL:111 - select wgarticles0_.IDFamille as IDFamille1_, wgarticles0_.ID as ID1_, wgarticles0_.ID as ID35_0_, wgarticles0_.IDFournisseur as IDFourni2_35_0_, wgarticles0_.IDFamille as IDFamille35_0_, wgarticles0_.IDTva as IDTva35_0_, wgarticles0_.IDMarque as IDMarque35_0_, wgarticles0_.S_Designation as S6_35_0_, wgarticles0_.R_PrixAchat as R7_35_0_, wgarticles0_.R_AchatMois as R8_35_0_, wgarticles0_.R_AchatCumule as R9_35_0_, wgarticles0_.R_PrixRevient as R10_35_0_, wgarticles0_.R_PrixUnitaire as R11_35_0_, wgarticles0_.R_QteVendue as R12_35_0_, wgarticles0_.R_QteVendueCumule as R13_35_0_, wgarticles0_.R_ChiffreAffaireMois as R14_35_0_, wgarticles0_.R_ChiffreAffaireCumule as R15_35_0_, wgarticles0_.R_Marge as R16_35_0_, wgarticles0_.R_MargeCumule as R17_35_0_, wgarticles0_.S_Observation as S18_35_0_, wgarticles0_.R_PrixTTC as R19_35_0_, wgarticles0_.S_Gencode as S20_35_0_ from wingsm.wgarticles wgarticles0_ where wgarticles0_.IDFamille=?
RAchatCumule : 900.0 (int)RAchatCumule : 900
hashcode de wgfamilllllllllllllllllllllllllles111 : 296209368
14:40:33,031 ERROR LazyInitializationException:42 - illegal access to loading collection
org.hibernate.LazyInitializationException: illegal access to loading collection
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:363)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
at org.hibernate.collection.PersistentSet.toString(PersistentSet.java:332)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at winGsmGWT.domain.Wgfamilles.hashCode(Wgfamilles.java:81)
at winGsmGWT.domain.Wgarticles.hashCode(Wgarticles.java:377)
at java.util.HashMap.put(Unknown Source)
at java.util.HashSet.add(Unknown Source)
at java.util.AbstractCollection.addAll(Unknown Source)
at org.hibernate.collection.PersistentSet.endRead(PersistentSet.java:352)
at org.hibernate.engine.loading.CollectionLoadContext.endLoadingCollection(CollectionLoadContext.java:260)
at org.hibernate.engine.loading.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:245)
at org.hibernate.engine.loading.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:218)
at org.hibernate.loader.Loader.endCollectionLoad(Loader.java:900)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:888)
at org.hibernate.loader.Loader.doQuery(Loader.java:752)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2015)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:59)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:587)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1743)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:366)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
at org.hibernate.collection.PersistentSet.toString(PersistentSet.java:332)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at winGsmGWT.domain.Wgfamilles.hashCode(Wgfamilles.java:81)
at winGsmGWT.domain.Wgarticles.hashCode(Wgarticles.java:377)
at java.lang.Object.toString(Object.java:219)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at java.util.AbstractCollection.toString(Unknown Source)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at accesDomain.WgarticlesManager.getListeArticles(WgarticlesManager.java:46)
at winGsmGWT.server.TestServiceImpl.listeArticles(TestServiceImpl.java:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.user.server.rpc.RPCCopy_GWT15.invoke(RPCCopy_GWT15.java:563)
at com.google.gwt.user.server.rpc.RPCCopy.invoke(RPCCopy.java:134)
at net.sf.gilead.gwt.PersistentRemoteService.processCall(PersistentRemoteService.java:149)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:86)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at com.google.gwt.dev.shell.GWTShellServlet.service(GWTShellServlet.java:289)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Unknown Source)
however my session is closed at the good place I think. I don't understand :s:s