Hibernate can not load correctly child-set at one-to-many mapping type when using hibernate 2.1.2; But when i change into
hibernate 2.0.3, hibernate work correctly.
Hibernate Vesion : 2.1.2
mapping documents
Parent mapping file
Code:
<?xml version="1.0" encoding="gb2312"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.tzsoft.test.hibernate.entity.TblGroup" table="TBL_Group">
<id name="groupId" column="Group_Id" type="string" length="50">
<generator class="uuid.hex"/>
</id>
<property name="groupName" column="Group_Name" type="string" length="100" not-null="true"/>
<set name="personSet" lazy="true" inverse="true" cascade="none">
<key column="Group_Id"/>
<one-to-many class="com.tzsoft.test.hibernate.entity.TblPerson"/>
</set>
</class>
</hibernate-mapping>
child mapping file
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.tzsoft.test.hibernate.entity.TblPerson" table="TBL_Person">
<composite-id unsaved-value="any">
<key-property name="personId" column="Person_Id" type="string" />
<key-many-to-one name="group" class="com.tzsoft.test.hibernate.entity.TblGroup">
<column name="Group_Id"/>
</key-many-to-one>
</composite-id>
<property name="personFirst" column="Person_First" type="string" length="32" not-null="true"/>
<property name="personBirthday" column="Person_Birthday" type="timestamp"/>
<property name="personSalary" column="Person_Salary" type="float"/>
<property name="personLast" column="Person_Last" type="string" length="32"/>
<property name="personInitial" column="Person_Initial" type="string" length="10"/>
</class>
</hibernate-mapping>
load java codeCode:
TblGroup group = (TblGroup)s.load(TblGroup.class, groupId);
Set persons = group.getPersonSet();
Iterator iter = persons.iterator();
while(iter.hasNext()){
TblPerson person = (TblPerson)iter.next();
System.out.println(person);
}
database: sql server 2000
sql scriptCode:
CREATE TABLE [dbo].[TBL_Group] (
[Group_Id] [char] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[Group_Name] [char] (100) COLLATE Chinese_PRC_CI_AS NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[TBL_Person] (
[Person_Id] [char] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[Group_Id] [char] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[Person_First] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
[Person_Birthday] [datetime] NULL ,
[Person_Salary] [float] NULL ,
[Person_Last] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
[Person_Initial] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
Thanks .