-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: ClassCastException import xml
PostPosted: Fri Feb 13, 2009 1:33 pm 
Newbie

Joined: Fri Feb 13, 2009 1:22 pm
Posts: 2
I am having problems importing XML with one-to-many element. Could anyone help me????

Thanks in advance.

The code that raises the exception is:

...
session.beginTransaction();
Session xmlSession = session.getSession(EntityMode.DOM4J);
Object x = xmlSession.merge(mapping_class,doc4j.getRootElement());
xmlSession.saveOrUpdate(mapping_class,x);
....

It is raised in merge function call.

Here is the exception:

Exception in thread "main" java.lang.ClassCastException: org.dom4j.tree.DefaultElement cannot be cast to java.util.Collection
at org.hibernate.type.CollectionType.replaceElements(CollectionType.java:500)
at org.hibernate.type.CollectionType.replace(CollectionType.java:574)
at org.hibernate.type.TypeFactory.replace(TypeFactory.java:505)
at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:392)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:319)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:167)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:81)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:704)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:688)
at org.criptolab.filetransformercontext.command.HibernateExportCommand.execute(HibernateExportCommand.java:57)
at org.criptolab.filetransformercontext.command.HibernateExportCommand.execute(HibernateExportCommand.java:75)
at org.criptolab.filetransformercontext.FileTransformerContext.commandExecute(FileTransformerContext.java:147)
at org.criptolab.filetransformercontext.FileTransformerContext.resolve(FileTransformerContext.java:175)
at org.criptolab.filetransformercontext.dia.Make4Dia.resolve(Make4Dia.java:96)
at org.criptolab.filetransformercontext.dia.Make4Dia.main(Make4Dia.java:250)


The hbm files:
Proyecto.hbm
<hibernate-mapping package="o2008.eui.cargainformes" >
<class name="Proyecto" node="PROYECTO" table="proyectos">
<id column="id_proyecto" name="id_proyecto" node="@id_proyecto" type="int"/>


<property column="referencia" name="referencia" node="REFERENCIA" type="string" unique="true"/>
<set name="recursos" node="recursos" embed-xml="true" optimistic-lock="false" cascade="all-delete-orphan" inverse="true" lazy="false">
<key column="id_recurso"/>
<one-to-many class="Recurso" embed-xml="true" node="RECURSO"/>
</set>
</class>
</hibernate-mapping>

Recurso.hbm
<hibernate-mapping package="o2008.eui.cargainformes" >
<class name="Recurso" node="RECURSO" table="recproy>
<id column="id_recurso" name="id_recurso" node="@id_recurso" type="integer"><generator class="sequence"><param name="sequence">recproy_id_recurso_seq</param></generator></id>
<many-to-one name="proyecto" column="id_proyecto" class="Proyecto" not-null="true" embed-xml="false" node="@id_proyecto"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 14, 2009 6:02 am 
Newbie

Joined: Fri Feb 13, 2009 1:22 pm
Posts: 2
replaceElements method in CollectionType.java source code does not support EntityMode.DOM4J. So I suposse this is because it fails:

Code:
   public Object replaceElements(
         Object original,
         Object target,
         Object owner,
         Map copyCache,
         SessionImplementor session) {
      // TODO: does not work for EntityMode.DOM4J yet!
      java.util.Collection result = ( java.util.Collection ) target;
                ...


I'll try to patch this code to enable it...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.