Hrmmm, I think there's an issue here...but its pretty subtle. Here's my test snippet:
User user = (User) userlist.get(0);
//Hibernate.initialize(user.getTeams());
//db.setInitializeLazy(true);
db.bind(user);
System.out.println(db.toXML());
Here's the output with no collections initialized:
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-custom datetime="03 September 2003 07:30:33">
<User id="N400004">
<userid>15656</userid>
<username>aaa</username>
<pass>aaa</pass>
<age>33</age>
<category id="N400031">809</category>
<!--elements of collection signups-->
<!--end of elements-->
<!--elements of collection results-->
<!--end of elements-->
<!--elements of collection teams-->
<!--end of elements-->
<!--elements of collection races-->
<!--end of elements-->
</User>
<Category id="N400031">
<categoryid>809</categoryid>
<categorydesc />
<categoryname>test</categoryname>
<!--elements of collection teams-->
<!--end of elements-->
<!--elements of collection results-->
<!--end of elements-->
<!--elements of collection users-->
<!--end of elements-->
</Category>
</hibernate-custom>
Here's the output with Hibernate.initialize(user.getTeams());
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-generic datetime="03 September 2003 06:42:32">
<object class="User" package="com.hib">
<uid name="userid" type="integer">15656</uid>
<property name="username" type="string">aaa</property>
<property name="pass" type="string">aaa</property>
<property name="age" type="integer">33</property>
<property name="category" uid="809" class="Category" package="com.hib" type="com.hib.Category"/>
<collection name="signups" class="java.util.Set" element-type="com.hib.Signup" lazy="uninitialized"/>
<collection name="results" class="java.util.Set" element-type="com.hib.Result" lazy="uninitialized"/>
<collection name="teams" class="java.util.Set" element-type="com.hib.Team" lazy="initialized"/>
<collection name="races" class="java.util.Set" element-type="com.hib.Race" lazy="uninitialized"/>
</object>
<object class="Category" package="com.hib">
<uid name="categoryid" type="integer">809</uid>
<property name="categorydesc" type="string"></property>
<property name="categoryname" type="string">test</property>
<collection name="teams" class="java.util.Set" element-type="com.hib.Team" lazy="uninitialized"/>
<collection name="results" class="java.util.Set" element-type="com.hib.Result" lazy="uninitialized"/>
<collection name="users" class="java.util.Set" element-type="com.hib.User" lazy="uninitialized"/>
</object>
</hibernate-generic>
As I step through the code, the renderProperty method correctly sees that the Teams set is initialized, correctly identifies it as a set, but for some reason thinks the set is null, so it doesn't add any elements to the document.
I think the problem stems from the fact that the User object and its associated Category object both have their own 0-n relationships to Teams. I tried serializing other object types and Databinder picked up the collections OK (although the default output format doesn't format the collection objects as child elements...bleh). Anyway, lemme know if you want this in JIRA.
My mappings:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="com.hib.User"
table="users"
>
<id
name="userid"
type="int"
column="userid"
>
<generator class="hilo"> <param name="table">hi_value</param> <param name="column">next_value</param> <param name="max_lo">100</param> </generator>
</id>
<property
name="username"
type="java.lang.String"
column="username"
not-null="true"
unique="true"
/>
<property
name="pass"
type="java.lang.String"
column="pass"
not-null="true"
/>
<property
name="age"
type="int"
column="age"
length="4"
/>
<!-- associations -->
<!-- bi-directional many-to-one association to Category -->
<many-to-one
name="category"
class="com.hib.Category"
not-null="true"
>
<column name="categoryid" />
</many-to-one>
<set
name="signups"
lazy="true"
inverse="true"
>
<key>
<column name="userid" />
</key>
<one-to-many
class="com.hib.Signup"
/>
</set>
<set
name="results"
lazy="true"
inverse="true"
>
<key>
<column name="userid" />
</key>
<one-to-many
class="com.hib.Result"
/>
</set>
<!-- bi-directional one-to-many association to Userteam -->
<set name="teams" table="userteam" lazy="true">
<key column="userid"/>
<many-to-many class="com.hib.Team" column="teamid"/>
</set>
<set name="races" table="result" lazy="true">
<key column="userid"/>
<many-to-many class="com.hib.Race" column="raceid"/>
</set>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="com.hib.Category"
table="category"
>
<id
name="categoryid"
type="int"
column="categoryid"
>
<generator class="hilo"> <param name="table">hi_value</param> <param name="column">next_value</param> <param name="max_lo">100</param> </generator>
</id>
<property
name="categorydesc"
type="java.lang.String"
column="categorydesc"
length="18"
/>
<property
name="categoryname"
type="java.lang.String"
column="categoryname"
not-null="true"
unique="true"
/>
<!-- associations -->
<set name="teams" table="categoryteams" lazy="true">
<key column="categoryid"/>
<many-to-many class="com.hib.Team" column="teamid"/>
</set>
<!-- bi-directional one-to-many association to Result -->
<set
name="results"
lazy="true"
inverse="true"
>
<key>
<column name="categoryid" />
</key>
<one-to-many
class="com.hib.Result"
/>
</set>
<!-- bi-directional one-to-many association to User -->
<set
name="users"
lazy="true"
inverse="true"
>
<key>
<column name="categoryid" />
</key>
<one-to-many
class="com.hib.User"
/>
</set>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class
name="com.hib.Team"
table="teams"
>
<id
name="teamid"
type="int"
column="teamid"
>
<generator class="hilo"> <param name="table">hi_value</param> <param name="column">next_value</param> <param name="max_lo">100</param> </generator>
</id>
<property
name="teamname"
type="java.lang.String"
column="teamname"
not-null="true"
unique="true"
/>
<property
name="teamdesc"
type="java.lang.String"
column="teamdesc"
/>
<property
name="minage"
type="int"
column="minage"
length="4"
/>
<property
name="maxage"
type="int"
column="maxage"
length="4"
/>
<set name="categories" table="categoryteams" lazy="true">
<key column="teamid"/>
<many-to-many class="com.hib.Category" column="categoryid"/>
</set>
<!-- bi-directional one-to-many association to Result -->
<set
name="results"
lazy="true"
inverse="true"
>
<key>
<column name="teamid" />
</key>
<one-to-many
class="com.hib.Result"
/>
</set>
<!-- bi-directional one-to-many association to Userteam -->
<set name="users" table="userteam" lazy="true">
<key column="teamid"/>
<many-to-many class="com.hib.User" column="userid"/>
</set>
</class>
</hibernate-mapping>