I have tried the following with 3.1.3 and 3.2.1:
create table test_parent(
parent_key NUMERIC(3) not null,
description varchar(40),
hibernate_version numeric(17),
CONSTRAINT pk_test_parent PRIMARY KEY( parent_key ) );
create table test_child(
parent_key NUMERIC(3) not null,
child_key NUMERIC(3) not null,
description varchar(40),
hibernate_version numeric(17),
CONSTRAINT pk_test_child PRIMARY KEY( parent_key, child_key ) );
INSERT INTO test_parent
(
parent_key,
description,
hibernate_version
)
VALUES
(
1,
'Test Parent',
0
);
INSERT INTO test_child
(
parent_key,
child_key,
description,
hibernate_version
)
VALUES
(
1,
1,
'Test Child',
0
);
INSERT INTO test_child
(
parent_key,
child_key,
description,
hibernate_version
)
VALUES
(
1,
3,
'Test Child',
0
);
INSERT INTO test_child
(
parent_key,
child_key,
description,
hibernate_version
)
VALUES
(
1,
5,
'Test Child',
0
);
INSERT INTO test_child
(
parent_key,
child_key,
description,
hibernate_version
)
VALUES
(
1,
10,
'Test Child',
0
);
TestParent.hbm.xml
<?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="hibernate.TestParent" table="test_parent">
<id column="parent_key" name="parentKey" type="integer">
<generator class="assigned"/>
</id>
<version column="hibernate_version" name="hibernateVersion" type="long" unsaved-value="null"/>
<property column="description" length="40" name="description" type="string"/>
<list name="childList"
inverse="true"
lazy="true"
cascade="all-delete-orphan">
<key column="parent_key"/>
<list-index column="child_key"/>
<one-to-many class="hibernate.TestChild"/>
</list>
</class>
</hibernate-mapping>
TestChild.hbm.xml
<?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="hibernate.TestChild" table="test_child">
<composite-id>
<key-property column="parent_key" length="3" name="parentKey" type="integer"/>
<key-property column="child_key" length="3" name="childKey" type="integer"/>
</composite-id>
<version column="hibernate_version" name="hibernateVersion" type="long" unsaved-value="null"/>
<property column="description" length="40" name="description" type="string"/>
</class>
</hibernate-mapping>
Query and code:
Iterator iterator =
session.createQuery(
"SELECT parent FROM TestParent parent LEFT JOIN parent.childList" )
.list( ).iterator( );
while ( iterator.hasNext( ) )
{
TestParent testParent = (TestParent) iterator.next( );
System.err.println( testParent );
for ( TestChild testChild : testParent.getChildList( ) )
{
System.err.println( testChild );
}
}
Creates the following output:
hibernate.TestParent@fd66a5[parentKey=1]
null
hibernate.TestChild@1389b3f[parentKey=1,childKey=1]
null
hibernate.TestChild@1a0b53e[parentKey=1,childKey=3]
null
hibernate.TestChild@1dafb4e[parentKey=1,childKey=5]
null
null
null
null
hibernate.TestChild@1a8d460[parentKey=1,childKey=10]
hibernate.TestParent@fd66a5[parentKey=1]
null
hibernate.TestChild@1389b3f[parentKey=1,childKey=1]
null
hibernate.TestChild@1a0b53e[parentKey=1,childKey=3]
null
hibernate.TestChild@1dafb4e[parentKey=1,childKey=5]
null
null
null
null
hibernate.TestChild@1a8d460[parentKey=1,childKey=10]
hibernate.TestParent@fd66a5[parentKey=1]
null
hibernate.TestChild@1389b3f[parentKey=1,childKey=1]
null
hibernate.TestChild@1a0b53e[parentKey=1,childKey=3]
null
hibernate.TestChild@1dafb4e[parentKey=1,childKey=5]
null
null
null
null
hibernate.TestChild@1a8d460[parentKey=1,childKey=10]
hibernate.TestParent@fd66a5[parentKey=1]
null
hibernate.TestChild@1389b3f[parentKey=1,childKey=1]
null
hibernate.TestChild@1a0b53e[parentKey=1,childKey=3]
null
hibernate.TestChild@1dafb4e[parentKey=1,childKey=5]
null
null
null
null
hibernate.TestChild@1a8d460[parentKey=1,childKey=10]
My issues are:
1) I get the same results 4 times
2) The childList seems to fill in non existant values with null records
Could someone help me with this or is this expected behavior and if so could someone point me to a link so i can understand it?
|