-->
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.  [ 4 posts ] 
Author Message
 Post subject: XML import - Mapping Exception: Unknown Entity
PostPosted: Tue Nov 29, 2005 3:14 am 
Newbie

Joined: Tue Nov 29, 2005 2:43 am
Posts: 9
I am using hibernate version 3.0.5. I am trying to export/import data from and to hibernate objects. I have been successfully managed to export the data from hibernate object using DOM4J.
However, when I try to import the same XML using dom4jsession it generates an error. Following is the call stack:

    org.hibernate.MappingException: Unknown entity: CategoryName
    at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:569)
    at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1089)
    at org.hibernate.event.def.DefaultReplicateEventListener.onReplicate(DefaultReplicateEventListener.java:56)
    at org.hibernate.impl.SessionImpl.replicate(SessionImpl.java:694)
    at wfp.service.CommonServiceImpl.replicateObject(CommonServiceImpl.java:14)
    at wfp.web.XmlDataHandler.importData(XmlDataHandler.java:111)
    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)



My mapping file 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"
    table="category_name"
    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" node="." embed-xml="true">
    <key column="category_name_id"/>
    <list-index column="display_order" base="0"/>
    <one-to-many class="SkillName" embed-xml="false" node="skillname"/>
    </list>

    <many-to-one name="wfp" column="wfp_id" not-null="true" node="wfp/@wfpid" embed-xml="false"/>
    </class>
    </hibernate-mapping>

Following is a part of the XML that I try to import:

    <CategoryName metadataid="1" version="16"><skillname>1</skillname><skillname>2</skillname><skillname>3</skillname><skillname>4</skillname><skillname>5</skillname><skillname>6</skillname><skillname>7</skillname><skillname>8</skillname><skillname>9</skillname><skillname>10</skillname><skillname>11</skillname><skillname>12</skillname><skillname>187</skillname><skillname>188</skillname><skillname>189</skillname><name>Infrastructure</name><description>Infrastructure skills include all the setup and configuration of the various tools and systems required for work to happen</description><displayorder>0</displayorder><wfp wfpid="1"/></CategoryName>


I am using the following code to import the data from the XML:

Code:
           Document doc = reader.read(file);       

               
            Element root = doc.getRootElement();
               
            Session session = HibernateWrapper.currentSession();
            Session dom4jSession = session.getSession(EntityMode.DOM4J);
       
            CommonService commonService = (CommonService) IoC.getFactory().getInstance("CommonService");
            Iterator i  = root.elementIterator();
            Transaction tx = dom4jSession.beginTransaction();
               
            while(i.hasNext())
            {
                 Element element = (Element) i.next();
                 dom4jSession.replicate("CategoryName", element,ReplicationMode.OVERWRITE);
                 session.flush();             
            }             
               
             tx.commit(); 



I have tried using saveorUpdate method instead of the replicate, but it did the same. Can someone help? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 6:58 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
I do not use dom4j, so I am not sure if I am right here.
But in method:

Code:
Session.replicate(String entityName, Object object, ReplicationMode replicationMode)


the entityName is related to an entityName in your mapping like:
Code:
   <class name="MyBase"
      table="base1"
      entity-name="MyBase1">


Not sure though.

_________________
dont forget to rate !


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 1:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
steckemetz is correct. The entity-name for the mapping you provided is actually "wfp.domain.CategoryName" since you did not override it in the mapping file. So one of two choices:
1) change the mapping:
Code:
<class name="CategoryName"   
        entity-name="CategoryName"
        table="category_name"
        node="CategoryName">
    ...


2) change the API call:
Code:
dom4jSession.replicate(
        CategoryName.class.getName(),
        element,
        ReplicationMode.OVERWRITE
);


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 10:01 pm 
Newbie

Joined: Tue Nov 29, 2005 2:43 am
Posts: 9
Thanks guys. I did as per Steve’s second suggestion and it worked!. If I put the entity-name it gave me some spurious errors.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.