-->
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: play with xml mapping
PostPosted: Wed May 18, 2005 7:39 pm 
Newbie

Joined: Wed May 18, 2005 6:48 pm
Posts: 4
Hello,

Some time ago I try with version 2.x but next I was reading about JDO and EJB and now I back to hibernate and start with version 3.x.

XML mapping is great idea. Just super ;]

I have got some data backuped in xml, I thought it is great chance to play with xml mapping.
I have 3 class:
A { int id; String name }
Parent extends A { Set children ... // instances of Child }
Child extends A { }

and I have got xml like this:
Code:
<root>
    <Parent id="100" name="parent">
        <Child id="111" name="child"/>
    </Parent>
</root>

And when I want save Parent object
Code:
        Element root = d.getRootElement();
        Node n = root.node(0);
        dom4jSession.save("test.Parent",n);

a catch exception like this:
Code:
instance not of expected entity type: test.A
org.hibernate.HibernateException: instance not of expected entity type: test.A
    at org.hibernate.persister.entity.BasicEntityPersister.getSubclassEntityPersister(BasicEntityPersister.java:2967)
    at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1083)
    at org.hibernate.id.Assigned.generate(Assigned.java:31)
    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:85)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
    at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
    at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
    at org.hibernate.impl.SessionImpl.save(SessionImpl.java:477)
    at test.ATest.testHello(ATest.java:63)


My hbm file looks like this:
Code:
<hibernate-mapping package="test">

   <class name="A" table="aa">
      <id name="id" node="@id"/>
                <discriminator column="class_type" type="string" length="10"/>
      <property name="name" column="name" not-null="true" type="string" length="63" node="@name"/>
               
                <subclass name="Parent" discriminator-value="parent" node="Parent">
                    <set name="children"  embed-xml="true" node=".">
                        <key column="parent_id"/>
                        <one-to-many class="Child"/>
                    </set>
                </subclass>
               
                <subclass name="Child" discriminator-value="child" node="Child">
                   
                </subclass>
   </class>
   
</hibernate-mapping>


uff :)
Everything looks fine. I can retrieve dom4j's node from database and it looks fine.
Code:
<Parent id="10" name="parent"><Child id="11" name="child"/></Parent>


Greetings
Flower


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 18, 2005 8:02 pm 
Newbie

Joined: Wed May 18, 2005 6:48 pm
Posts: 4
hmm ... I think this line:
dom4jSession.save("test.Parent",n);
is wrong ;)
So my question is... How and Can I store dom4j node/element ?

Greetings
Flower


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.