Hibernate version: 3.2
Hello,
I have realized some strange behavior on loading collection-properties.
(After reading the book "Java Persist with Hibernate", searching in the documentation and in the Internet I am still without any answer)
Let's consider an entity which property is a collection.
This is configured as the following:
Code:
<class dynamic-insert="false" dynamic-update="false"
entity-name="defaultexample " select-before-update="false">
<id column="XHDOC" name=" XHDOC" type="string">
<generator class="native"/>
</id>
<bag name="DOCTYPES" fetch="subselect" table=" DEFAULTEXAMPLEDOCTYPES">
<key column="HDOC "/>
<one-to-many entity-name="defaultexampleDOCTYPES"/>
<loader query-ref="sysdoctypes"/>
</bag>
…..</class>
The respective entity is defined as a class:
Code:
<class dynamic-insert="false" dynamic-update="false"
entity-name="defaultexampleDOCTYPES" select-before-update="false">
<id column="HDOC" name="HDOC" type="string">
<generator class="native"/>
</id>
<property column="MULTIVAL" name="MULTIVAL " type="string"/>
</class>
As you have seen, I am using the sql query to load the belonging collections:
Code:
<sql-query name="sysdoctypes">
<load-collection alias="d" role=" defaultexample.DOCTYPES"/>
select {d.*}
from DEFAULTEXAMPLEDOCTYPES d
where d.HDOC=?
</sql-query>
After the issuing the following query
Code:
String stmt = "from defaultexample d where d.XHDOC = :id ";
List result = session.createQuery(stmt2).setParameter("id",
"7B17AFBF645441420F0001000000F80B000000000000").list();
The result of the query is a list of maps:
Code:
[{...$type$=defaultexample, ..., XHDOC=7B17AFBF645441420F0001000000F80B000000000000, ….
SYSDOCTYPES=
[{MULTIVAL=TIF, HDOC=7B17AFBF645441420F0001000000F80B000000000000, $type$=defaultexampleSYSDOCTYPES},
{MULTIVAL=TIF, HDOC=7B17AFBF645441420F0001000000F80B000000000000, $type$=defaultexampleSYSDOCTYPES},
{MULTIVAL=TIF, HDOC=7B17AFBF645441420F0001000000F80B000000000000, $type$=defaultexampleSYSDOCTYPES},
{MULTIVAL=TIF, HDOC=7B17AFBF645441420F0001000000F80B000000000000, $type$=defaultexampleSYSDOCTYPES},
{MULTIVAL=TIF, HDOC=7B17AFBF645441420F0001000000F80B000000000000, $type$=defaultexampleSYSDOCTYPES},
{MULTIVAL=TIF, HDOC=7B17AFBF645441420F0001000000F80B000000000000, $type$=defaultexampleSYSDOCTYPES}], …]
The strangest thing here is that the count of the returned multivalues is correct (it must be 6 values) but every value is set at TIF, however it must be:
Code:
[TIF
gif
htm
pdf
doc
jpg]
That means, each value of the returned by Hibernate List is set to the first value of the correct result. Do I miss something in configuration? What would be the correct way to return such collections.
Thank you very much in advance for your help!
Larysa