hello.
i'm (new to hibernate and) using verion 3.0.1 to generate an XML view of my data in Sybase 12, using jdk1.4.2_04.
it seems to work fairly fine for me (i still have to tweak some mappings), except that i have a type called TaskItem, which has two associations to classes OF THE SAME TYPE: TaskEvent.
one association is called "taskEventByCreateEventId" and the other is called "taskEventByLastEventId". both these names are sniffed from the foreign keys in the database schema, by MiddleGen2.1.
now, when i do a retrieval from the database, the generated XML document correctly retrieves all the data i want, but the TaskItem node (the root node) has two sub-elements called either "taskEventByCreateEventId" or "taskEventByLastEventId". the name depends on which association i have defined second in my TaskItem.hbm descriptor. what i want is one association called "taskEventByCreateEventId" and one called "taskEventByLastEventId".
note that this only happens if i specify the attribute embed-xml="true" FOR BOTH ASSOCIATIONS. if i set embed-xml="false", even for only one of the associations, then the associations (nodes in my XML doc) are named correctly!
and it only happens if the referenced TaskEvents have the same ID.
is there some config which i am neglecting, or some optimisation that is happening that i don't know about?
find below the relevant sections of config files.
many thanks.
donall.
from TaskItem.hbm:
Code:
<?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>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="com.ebzc.utils.taskpersistence.TaskItem"
table="TASK_ITEM"
node="TaskItem"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="TASK_ITEM"
</meta>
<!-- bi-directional many-to-one association to TaskEvent -->
<many-to-one
name="taskEventByLastEventId"
class="com.blah.TaskEvent"
not-null="true"
embed-xml="true"
>
<meta attribute="field-description">
@hibernate.many-to-one
not-null="true"
@hibernate.column name="LAST_EVENT_ID"
</meta>
<column name="LAST_EVENT_ID" />
</many-to-one>
<!-- bi-directional many-to-one association to TaskEvent -->
<many-to-one
name="taskEventByCreateEventId"
class="com.blah.TaskEvent"
not-null="true"
embed-xml="true"
>
<meta attribute="field-description">
@hibernate.many-to-one
not-null="true"
@hibernate.column name="CREATE_EVENT_ID"
</meta>
<column name="CREATE_EVENT_ID" />
</many-to-one>
</class>
</hibernate-mapping>
from TaskEvent.hbm:Code:
<?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>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="com.blah.TaskEvent"
table="TASK_EVENT"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="TASK_EVENT"
</meta>
<id
name="eventId"
type="java.math.BigDecimal"
column="EVENT_ID"
>
<meta attribute="field-description">
@hibernate.id
generator-class="assigned"
type="java.math.BigDecimal"
column="EVENT_ID"
</meta>
<generator class="assigned" />
</id>
<property
name="eventTimestamp"
type="java.sql.Timestamp"
column="EVENT_TIMESTAMP"
length="23"
>
<meta attribute="field-description">
@hibernate.property
column="EVENT_TIMESTAMP"
length="23"
</meta>
</property>
<!-- Associations -->
</class>
</hibernate-mapping>