Im using hibernate 3.0.5. I have used dom4j to export the objects into an xml. Then, I use the session.replicate() to import the data. All these work without any problem as far as the data that exported are still in the database. When I import, it goes and overwites the objects from xml to the database.
However, the problem occurs when I try to import while there is no data in the database. I get the following call stack:
Hibernate: /* get version wfp.domain.WFP */ select version from wfp where wfp_id =?
Hibernate: /* get version wfp.domain.CategoryName */ select version from category_name where category_name_id =?
2005-12-01 15:50:36,072 [PoolThread-1] ERROR wfp.web.XmlDataHandler - import
java.lang.ClassCastException: java.lang.Long
at org.hibernate.property.Dom4jAccessor$ElementGetter.get(Dom4jAccessor.java:190)
at org.hibernate.tuple.AbstractTuplizer.getVersion(AbstractTuplizer.java:159)
at org.hibernate.persister.entity.BasicEntityPersister.getVersion(BasicEntityPersister.java:2954)
at org.hibernate.persister.entity.BasicEntityPersister.isTransient(BasicEntityPersister.java:2715)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
at org.hibernate.engine.ForeignKeys$Nullifier.isNullifiable(ForeignKeys.java:137)
at org.hibernate.engine.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:69)
at org.hibernate.engine.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:47)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:234)
at org.hibernate.event.def.DefaultReplicateEventListener.onReplicate(DefaultReplicateEventListener.java:111)
at org.hibernate.impl.SessionImpl.replicate(SessionImpl.java:694)
at org.hibernate.engine.Cascades$9.cascade(Cascades.java:240)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:771)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:895)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:792)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascade(Cascades.java:847)
at org.hibernate.event.def.DefaultReplicateEventListener.performReplication(DefaultReplicateEventListener.java:163)
at org.hibernate.event.def.DefaultReplicateEventListener.onReplicate(DefaultReplicateEventListener.java:94)
at org.hibernate.impl.SessionImpl.replicate(SessionImpl.java:694)
at wfp.service.CommonServiceImpl.replicateObject(CommonServiceImpl.java:23)
at wfp.web.XmlDataHandler.importData(XmlDataHandler.java:202)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
at javax.faces.component.UICommand.broadcast(UICommand.java:106)
at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:164)
at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:316)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:374)
at org.mortbay.jetty.servlet.WebApplicationHandler$Chain.doFilter(WebApplicationHandler.java:529)
at wfp.web.HibernateFilter.doFilter(HibernateFilter.java:37)
at org.mortbay.jetty.servlet.WebApplicationHandler$Chain.doFilter(WebApplicationHandler.java:520)
at wfp.web.AccessControlFilter.doFilter(AccessControlFilter.java:79)
at org.mortbay.jetty.servlet.WebApplicationHandler$Chain.doFilter(WebApplicationHandler.java:520)
at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:472)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:520)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1451)
at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:515)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1403)
at org.mortbay.http.HttpServer.service(HttpServer.java:889)
at org.mortbay.http.HttpConnection.service(HttpConnection.java:831)
at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:998)
at org.mortbay.http.HttpConnection.handle(HttpConnection.java:848)
at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:222)
at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:325)
at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:520)
[GC 17587K->16766K(24052K), 0.0120059 secs]
My object mapping is as follows:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="wfp.domain">
<class name="CategoryName"
entity-name="wfp.domain.CategoryName"
table="category_name"
dynamic-update="true"
node="CategoryName">
<id name="metadataId" column="category_name_id" node="@metadataid">
<generator class="native"/>
</id>
<version name="version" unsaved-value="null" node="version"/>
<property name="name" type="string" not-null="true" unique="true" node="name"/>
<property name="description" type="string" not-null="true" node="description"/>
<property name="displayOrder" column="display_order" not-null="true" node="displayorder"/>
<list name="skills" cascade="all" inverse="true" lazy="false">
<key column="category_name_id"/>
<list-index column="display_order" base="0"/>
<one-to-many class="SkillName"/>
</list>
<many-to-one name="wfp" column="wfp_id" not-null="true" node="WFP/@wfpid" embed-xml="false"/>
</class>
</hibernate-mapping>
I try to replicate the object as follows:
Code:
Element element = (Element) itr.next();
String className = Class.forName("wfp.domain." + element.getName()).getName();
session.replicate(className, element, ReplicationMode.OVERWRITE);
I have gor all the getters and setters for id(Long) and version(Integer) Can someone help? [/list]