-->
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.  [ 1 post ] 
Author Message
 Post subject: reading instance referring to class with subclass from XML
PostPosted: Sun Aug 06, 2006 7:56 am 
Newbie

Joined: Sun Mar 26, 2006 6:31 am
Posts: 3
I have a class MyClass that has a subclass MySubclass,
and one instance of MyClass in the database with id=1.
Besides, there is a class MyRefClass that references
MyClass (many-to-one).

When I try to replicate an instance of MyRefClass from
XML into the database that references the existing instance of MyClass,
I get the following error:

Code:
Exception in thread "main" org.hibernate.HibernateException: instance not of expected entity type: MyClass
   at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassEntityPersister(AbstractEntityPersister.java:3301)
   at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1311)
   at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:180)
   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:263)
   at org.hibernate.event.def.DefaultReplicateEventListener.onReplicate(DefaultReplicateEventListener.java:117)
   at org.hibernate.impl.SessionImpl.fireReplicate(SessionImpl.java:916)
   at org.hibernate.impl.SessionImpl.replicate(SessionImpl.java:903)
   at Main.hibtest(Main.java:90)
   at Main.main(Main.java:30)


The method getSubclassEntityPersister() does not seem to work
here - I also doubt if the "TODO" in the code would help, because
the "instance" passed is a Long (i.e., the identifier of MyClass).

Is this a bug? Does anyone know a workaround? I found
http://opensource.atlassian.com/project ... se/HHH-422
but am not sure if this is about the same thing, and besides it
only refers to 3.0.

The XML File:
Code:
<?xml version="1.0" encoding="UTF-8"?>

<MyRefClass>
  <id>1</id>
  <myClass>1</myClass>
</MyRefClass>


Hibernate version: 3.1.3

Mapping documents:

MyClass.hbm.xml:
Code:
<hibernate-mapping>
        <class name="MyClass" table="MyClass">
            <id name="id" column="id" type="long">
               <generator class="native"/>
            </id>
            <discriminator column="discrim" type="string"/>
            <subclass name="MySubclass" discriminator-value="MySubclass"/>
        </class>
</hibernate-mapping>


MyRefClass.hbm.xml:
Code:
<hibernate-mapping>
        <class name="MyRefClass" table="MyRefClass" node="MyRefClass">
                <id name="id" column="id" type="long">
                    <generator class="native"/>
                </id>
                <many-to-one name="myClass" column="myClassId" embed-xml="false"/>
        </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
         Transaction tx = hibernateSession.beginTransaction();

         Session dom4jsession = hibernateSession.getSession(EntityMode.DOM4J);

         SAXReader reader = new SAXReader();
         Document document = null;
         try {
            document = reader.read(new FileReader("/tmp/ttt.xml"));
         } catch (Exception e) {
            System.out.println("Error reading xml");
            System.exit(0);
         }
         
         Element el = (Element)document.selectSingleNode("MyRefClass");
            
         dom4jsession.replicate(el,ReplicationMode.OVERWRITE);
            
         tx.commit();


Name and version of the database you are using: MySQL 5


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

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.