Hibernate version:
3.2
Mapping documents:
<hibernate-mapping package="wpi.metier">
<class name="Contrat" node="r">
<composite-id name="contratPK">
<key-property name="id" type="string" node="@id"/>
<key-property name="code" type="string" node="code"/>
<key-property name="validite" type="string" node="validite"/>
</composite-id>
<property name="client" type="string" node="client"/>
<property name="contrat" type="string" node="contrat"/>
<property name="contact" type="string" node="contact"/>
<property name="famFile" type="string" node="famFile"/>
<property name="famUrl" type="string" node="famUrl"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Session dom4jSession = session.getSession(EntityMode.DOM4J);
Session pojoSession = session.getSession(EntityMode.POJO);
Transaction transaction = session.beginTransaction();
/* Lecture du document avec DOM4J */
SAXReader saxReader = new SAXReader();
String xmlfile= this.getRequest().getSession(false).getServletContext().getRealPath("/") + "ressources" + java.io.File.separator + "xml" + java.io.File.separator + "wpi-contrats.xml";
Document xmldb = saxReader.read(xmlfile);
List users = xmldb.selectNodes("//r");
Iterator it = users.iterator();
while(it.hasNext()){
Element element = (Element) it.next();
/* Recuperation de la clé composite */
ContratPK contratpk = new ContratPK();
contratpk.setId(element.attributeValue("id"));
contratpk.setCode(element.elementText("code"));
contratpk.setValidite(element.elementText("validite"));
/* Pour tester ... */
contrat = new Contrat();
contrat.setId(element.attributeValue("id"));
contrat.setCode(element.elementText("code"));
contrat.setValidite(element.elementText("validite"));
contrat.setClient(element.elementText("client"));
contrat.setContact(element.elementText("contact"));
contrat.setContrat(element.elementText("contrat"));
contrat.setFamFile(element.elementText("famFile"));
contrat.setFamUrl(element.elementText("famUrl"));
contrat.setContratPK(contratpk);
pojoSession.merge("wpi.metier.Contrat",contrat);
pojoSession.flush();
Object pojo = pojoSession.get("wpi.metier.Contrat",contratpk );
Object dom4j = dom4jSession.get("wpi.metier.Contrat",contratpk );
Ce code n'est pas tout à fait cohérent mais devait me permettre de "découvrir" la syntaxe extacte de la representation XML de mes elements.
The pojoSession.get work fine but the dom4jSession.get fail with a ClassCastException
Full stack trace of any exception that occurs:
java.lang.ClassCastException : wpi.metier.ContratPK
at org.hibernate.property.Dom4jAccessor$AttributeGetter.get(Dom4jAccessor.java:171)
at org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:61)
at org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:67)
at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:307)
at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:158)
at org.hibernate.engine.EntityKey.generateHashCode(EntityKey.java:103)
at org.hibernate.engine.EntityKey.<init>(EntityKey.java:47)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:76)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:799)
at wpi.databean.ListeContratsDBBean.select(ListeContratsDBBean.java:88)
at wpi.singleton.SingletonContrats.init(SingletonContrats.java:96)
at wpi.singleton.SingletonContrats.<init>(SingletonContrats.java:26)
at wpi.singleton.SingletonContrats.getInstance(SingletonContrats.java:36)
at org.apache.jsp.jsp.Contrats_jsp._jspService(Contrats_jsp.java:141)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
Help please !!!
It's a bug ;-( !!!! ????
|