Hibernate version:3.0.2
I have included the output of running this identical process using the 3.0.1 hibernate.jar and the just released 3.0.2 jar.
Below there are two xml fragments, one for each version.
For some reason, using the 3.0.2 release, the <set> mappings for "races" and "ethnicities" appear in the document twice. At the beginning, and also at the end. (Note: actual tests contained several more property mappings which were removed for brevity.)
Mapping documents:Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="PersonVO" table="PRSN" node="person">
<id column="PRSN_ID" name="personId" type="java.lang.Long">
<generator class="native"/>
</id>
<timestamp column="LST_MODIFIED_ON" name="timeLastModified"/>
<set name="ethnicities" table="PRSN_ETHNICITY" inverse="true" cascade="all,delete-orphan">
<key column="PRSN_ID"/>
<one-to-many class="PersonEthnicityVO"/>
</set>
<set name="races" table="PRSN_RACE" inverse="true" cascade="all,delete-orphan" >
<key column="PRSN_ID"/>
<one-to-many class="PersonRaceVO"/>
</set>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="PersonRaceVO" table="PRSN_RACE" node="person-race">
<id column="PRSN_RACE_ID" name="personRaceId" type="java.lang.Long">
<generator class="native"/>
</id>
<many-to-one column="PRSN_ID" name="person" class="PersonVO" not-null="true" embed-xml="false"/>
<many-to-one column="RACE_DMGR_ID" name="raceDmgr" class="RaceDmgrVO" not-null="true" embed-xml="false"/>
</class>
</hibernate-mapping>
... PersonEthnicityVO mapping is almost identical to above...
Code between sessionFactory.openSession() and session.close():Code:
XMLWriter writer = ... create new XMLWriter
Session s = session.getSession(EntityMode.DOM4J);
List results = s.createQuery("from ClientVO client").list();
for (Iterator i = results.iterator(); i.hasNext();) {
Element e = (Element) i.next();
writer.write(e);
}
... close writer
3.0.1 results
Code:
<person>
<personId>1</personId>
<timeLastModified>2005-03-29 11:34:04</timeLastModified>
<ethnicities>
<person-ethnicity>
<personEthnicityId>448012</personEthnicityId>
<person>1</person>
<ethnicityDmgr>1</ethnicityDmgr>
</person-ethnicity>
<person-ethnicity>
<personEthnicityId>448011</personEthnicityId>
<person>1</person>
<ethnicityDmgr>102</ethnicityDmgr>
</person-ethnicity>
<person-ethnicity>
<personEthnicityId>448034</personEthnicityId>
<person>1</person>
<ethnicityDmgr>103</ethnicityDmgr>
</person-ethnicity>
</ethnicities>
<races>
<person-race>
<personRaceId>460016</personRaceId>
<person>1</person>
<raceDmgr>1</raceDmgr>
</person-race>
<person-race>
<personRaceId>460014</personRaceId>
<person>1</person>
<raceDmgr>3</raceDmgr>
</person-race>
</races>
</person>
3.0.2 results
Code:
<person>
<personId>1</personId>
<ethnicities>
<person-ethnicity>
<personEthnicityId>448012</personEthnicityId>
<person>1</person>
<ethnicityDmgr>1</ethnicityDmgr>
</person-ethnicity>
<person-ethnicity>
<personEthnicityId>448011</personEthnicityId>
<person>1</person>
<ethnicityDmgr>102</ethnicityDmgr>
</person-ethnicity>
<person-ethnicity>
<personEthnicityId>448034</personEthnicityId>
<person>1</person>
<ethnicityDmgr>103</ethnicityDmgr>
</person-ethnicity>
</ethnicities>
<races>
<person-race>
<personRaceId>460016</personRaceId>
<person>1</person>
<raceDmgr>1</raceDmgr>
</person-race>
<person-race>
<personRaceId>460014</personRaceId>
<person>1</person>
<raceDmgr>3</raceDmgr>
</person-race>
</races>
<timeLastModified>2005-03-29 11:34:04</timeLastModified>
<ethnicities>
<person-ethnicity>
<personEthnicityId>448012</personEthnicityId>
<person>1</person>
<ethnicityDmgr>1</ethnicityDmgr>
</person-ethnicity>
<person-ethnicity>
<personEthnicityId>448011</personEthnicityId>
<person>1</person>
<ethnicityDmgr>102</ethnicityDmgr>
</person-ethnicity>
<person-ethnicity>
<personEthnicityId>448034</personEthnicityId>
<person>1</person>
<ethnicityDmgr>103</ethnicityDmgr>
</person-ethnicity>
</ethnicities>
<races>
<person-race>
<personRaceId>460016</personRaceId>
<person>1</person>
<raceDmgr>1</raceDmgr>
</person-race>
<person-race>
<personRaceId>460014</personRaceId>
<person>1</person>
<raceDmgr>3</raceDmgr>
</person-race>
</races>
</person>