It's kind of strange the following situation, I think. When we have a collection that's loaded "lazy", like the documentation says, we use a "left join fetch" to load the "set". The 1) example works but the 2) doesn't by giving me the following error:
Code:
java.lang.ClassCastException
Did I miss something?
Can someone please explain me this point?
Here's the two examples:
1)
Code:
res = session.find(
"select he " +
"from vo.Ensaio e " +
"left join e.historicoEnsaios he where e.tabela = ?",
tabela,
Hibernate.STRING
);
2)
Code:
res = session.find(
"select he " +
"from vo.Ensaio e " +
"left join [b]fetch[/b] e.historicoEnsaios he where e.tabela = ?",
tabela,
Hibernate.STRING
);
-----------------------------------------------------
Mapping file (generated with Middlegen R3)
-----------------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//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="vo.Ensaio"
table="ensaio"
>
<id
name="id"
type="long"
column="id"
>
<generator class="increment" />
</id>
<property
name="referencia"
type="java.lang.String"
column="referencia"
not-null="true"
length="-1"
/>
<!-- associations -->
<!-- bi-directional one-to-many association to HistoricoEnsaio -->
<set
name="historicoEnsaios"
lazy="true"
inverse="true"
>
<key>
<column name="ensaio_fk" />
</key>
<one-to-many
class="vo.HistoricoEnsaio"
/>
</set>
</class>
</hibernate-mapping>