-->
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: Unable to import xml on subclass nodes of a collection
PostPosted: Sun May 01, 2005 6:16 pm 
Newbie

Joined: Mon Mar 14, 2005 11:50 am
Posts: 9
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.0.2

Mapping documents:
<hibernate-mapping package="com.eko.cims.model.dict" >

<class name="Event" table="Events"
rowid="rowid" node="event" >

<id name="id" type="long" column="event_id"
access="field" node="@id" unsaved-value="0" >
<generator class="sequence">
<param name="sequence" >eventSeq</param>
</generator>
</id>

<discriminator column="type_id" type="string" insert="false" />

<!-- <version column="chg_ts" name="changeTimestamp"
type="timestamp" unsaved-value="null" access="field" node="@version" /> -->
<property name="changeUserId" type="string"
column="chg_user_id" not-null="true" access="field" node="@changeuserid" />
<property name="code" type="long"
column="event_code" access="field" node="@eventcode" unique="true" />
<property name="description" type="string"
column="desc_txt" not-null="true" access="field" node="@description" />

<many-to-one name="type"
column="type_id"
access="field" not-null="true"
node="eventtype" embed-xml="true"
/>

<!-- <bag name="categories" table="EventCategoryMap" embed-xml="false"
access="field" node="." inverse="true" >
<key column="event_id"/>
<many-to-many column="category_id" class="Category"
node="category/@id" embed-xml="false" />
</bag> -->

<bag name="constraints" table="EventConstraints" embed-xml="true"
access="field" node="." >
<key column="event_id"/>
<one-to-many class="EventConstraint"
node="constraint" embed-xml="true" />
</bag>

<subclass name="AlphaNumericEvent"
discriminator-value="10" node="alphanumericevent">
<join table="AlphaNumericEvents">

<key column="event_id"/>

<property name="changeUserId" type="string"
column="chg_user_id" not-null="true" access="field" node="@changeuserid" />
<property name="defaultValue" type="string"
column="default_txt" access="field" node="@default" />
<property name="timed" type="boolean"
column="timed" access="field" node="@timed" />
<property name="format" type="string"
column="format_txt" access="field" node="@format" />
</join>
</subclass>
</class>

Collection reference causing problems(From a category class):
<bag name="events" table="EventCategoryMap"
access="field" embed-xml="true" node="." cascade="all">
<key column="category_id" not-null="true" />
<many-to-many column="event_id" embed-xml="true"
class="Event" node="event" />
</bag>


Code between sessionFactory.openSession() and session.close():
Session dom4jSession = session.getSession(EntityMode.DOM4J);
Transaction tx = null;
Document transformedDoc = null;
try {
tx = session.beginTransaction();

//Read our documents in
SAXReader reader = new SAXReader();
Document sourceDoc = reader.read(source);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(
new StreamSource( template )
);

// now lets style the given document
DocumentSource sourceXml = new DocumentSource( sourceDoc );
DocumentResult result = new DocumentResult();
transformer.transform( sourceXml, result );
transformedDoc = result.getDocument();

//Now actually import it
importDocument(transformedDoc, dom4jSession);

//Ensure things get flushed now..
dom4jSession.flush();
tx.commit();
} catch (Throwable t) {
try { tx.rollback(); } catch (Exception ignore) { }
log.fatal("Error importing file, transaction rolled back. ", t);
try {
if (transformedDoc != null) prettyPrint(transformedDoc, System.out);
} catch (Throwable et) {}
throw new RuntimeException(t);
}


Full stack trace of any exception that occurs:
2005-05-01 18:06:47,875 DEBUG - - Cascades - processing cascade ACTION_SAVE_UPDATE for: com.eko.cims.model.dict.Category
2005-05-01 18:06:47,875 DEBUG - - Cascades - cascade ACTION_SAVE_UPDATE for collection: com.eko.cims.model.dict.Category.events
2005-05-01 18:06:47,875 DEBUG - - Cascades - cascading to saveOrUpdate: com.eko.cims.model.dict.Event
2005-05-01 18:06:47,984 DEBUG - - JDBCTransaction - rollback
2005-05-01 18:06:47,984 DEBUG - - JDBCTransaction - rolled back JDBC Connection
2005-05-01 18:06:47,984 FATAL - - DictionaryImporter - Error importing file, transaction rolled back.
org.hibernate.HibernateException: instance not of expected entity type: com.eko.cims.model.dict.Event
at org.hibernate.persister.entity.BasicEntityPersister.getSubclassEntityPersister(BasicEntityPersister.java:2967)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1025)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:408)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:82)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:432)
at org.hibernate.engine.Cascades$5.cascade(Cascades.java:153)
at org.hibernate.engine.Cascades.cascade(Cascades.java:721)
at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:860)
at org.hibernate.engine.Cascades.cascade(Cascades.java:739)
at org.hibernate.engine.Cascades.cascade(Cascades.java:817)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:362)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:264)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:159)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:96)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:432)
at com.eko.cims.dict.DictionaryImporter.importDocument(DictionaryImporter.java:158)
at com.eko.cims.dict.DictionaryImporter.importSource(DictionaryImporter.java:108)
at com.eko.cims.model.dict.XmlExportTest.testImportDictionary(XmlExportTest.java:59)


Name and version of the database you are using:Oracle 10g

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:debug

Can't find a way to do a DOM4J session import of xml entity data. I have a set of classes that extend a base class using the subclass per table with a discriminator setup, and another class that holds a collection reference to their superclass. The class containing the collection reference is the one that needs to handle the xml data import, but I can't determine a good way of getting it to recognize my subclass instances. When I specify that all of the subclass nodes have a node attribute of the main superclass I am able to get Hibernate to recognize the node, but the collection mapping only allows for one node name. I get the above mentioned errors when attempting to map the collection via the superclass and node.

I can see that the BasicEntityPersister.getSubclassEntityPersister logic won't work in my case, because the obeject passed into the method is an instance of a DOM4J node element, not an actual entity. So the subsequent lookups in the mappedSubclass map don't return anything useful. A many-to-any sort of setup would be nice, but I didn't see anything in the DTD that would allow me to specify a nodename for a specific class when doing a collection mapping.

The only way I've been able to make anything sort of work is by specifying the class name on each individual Dom4j node as I iterate through them, ie with Session.saveOrUpdatte(String fullClassName, Element node). Maybe the many-to-any could use a discriminator value based on an attribute of a node? Or, even better would be for it to see that my superclass has a set of subclasses and build an additional sort of mapping for their node names so it has a complete view in the collection when doing an EntityMode.DOM4J parse of data.. ?.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 15, 2005 12:47 pm 
Beginner
Beginner

Joined: Thu Apr 07, 2005 5:12 pm
Posts: 27
Location: Hamburg
Did you find any solution? Still have the same problem.


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.