I am trying to to an eager join fetch of a ManyToOne association using
session.createQuery("from OrigemVO obj").list(),
but that always executes a select fetch type.
usin session.createCriteria(OrigemVO.class).list() works, but I think that is an Hibernate bug.
I opened an issue in
http://opensource.atlassian.com/projects/hibernate/browse/ANN-627 but that was rejected. Can anyone help me ? I canĀ“t use Criteria in my code because it is already in production.
Hibernate version: 3.2.0 GA
Mapping documents:
@Entity
@Table(name="ORIGENS", schema="JCOMPANY")
public class OrigemVO {
@Id
@Column (name = "CD_ORIGEM", nullable=false)
private Long id;
@SuppressWarnings("unchecked")
@ManyToOne (targetEntity = JurisdicaoVO.class, fetch = FetchType.EAGER)
@JoinColumn (name = "CD_JURISDICAO", nullable=false)
@Fetch(FetchMode.JOIN)
private Jurisdicao jurisdicao;
... Getters and setters ommitted ...
}
@Entity
@Table(name="JURISDICAO", schema="JCOMPANY")
public class JurisdicaoVO {
@Id
@Column (name = "CD_JURISDICAO", nullable=false)
private Long id;
@Column (name = "DS_JURISDICAO", nullable=false, length=40)
private String dsJurisdicao;
}
Code between sessionFactory.openSession() and session.close():
session.createQuery("from OrigemVO").list();
Name and version of the database you are using:
Oracle 10g
The generated SQL (show_sql=true):
select
origemvo0_.CD_ORIGEM as CD1_1_,
origemvo0_.VERSAO as VERSAO1_,
origemvo0_.DT_ALTERACAO as DT3_1_,
origemvo0_.NM_USUARIO as NM4_1_,
origemvo0_.DS_ORIGEM as DS5_1_,
origemvo0_.SG_UF as SG6_1_,
origemvo0_.CD_JURISDICAO as CD9_1_,
origemvo0_.COD_TST as COD7_1_,
origemvo0_.COD_IBGE as COD8_1_
from
JCOMPANY.ORIGENS origemvo0_
select
jurisdicao0_.CD_JURISDICAO as CD1_0_0_,
jurisdicao0_.DS_JURISDICAO as DS2_0_0_
from
JCOMPANY.JURISDICAO jurisdicao0_
where
jurisdicao0_.CD_JURISDICAO=?
Should Be:
select
this_.CD_ORIGEM as CD1_1_1_,
this_.VERSAO as VERSAO1_1_,
this_.DT_ALTERACAO as DT3_1_1_,
this_.NM_USUARIO as NM4_1_1_,
this_.DS_ORIGEM as DS5_1_1_,
this_.SG_UF as SG6_1_1_,
this_.CD_JURISDICAO as CD9_1_1_,
this_.COD_TST as COD7_1_1_,
this_.COD_IBGE as COD8_1_1_,
jurisdicao2_.CD_JURISDICAO as CD1_0_0_,
jurisdicao2_.DS_JURISDICAO as DS2_0_0_
from
JCOMPANY.ORIGENS this_
inner join
JCOMPANY.JURISDICAO jurisdicao2_
on this_.CD_JURISDICAO=jurisdicao2_.CD_JURISDICAO
[/url]