【发布时间】:2015-09-23 01:45:55
【问题描述】:
我正在尝试在 JPA 2 中进行一些查询,但它不断调用另一个查询来获取依赖项的信息
我的课程是:
@Entity
@Table(name = "tbltranslados")
public class Traslado implements Serializable {
@OneToOne(optional = true, mappedBy = "traslado", fetch = FetchType.LAZY)
private TrasladoHora hora;
}
@Entity
@Table(name = "tbltranshora")
public class TrasladoHora implements Serializable {
@OneToOne(optional = false,fetch=FetchType.LAZY)
@JoinColumn(nullable = false, name = "thr_TransladosID")
private Traslado traslado;
}
我这样调用查询:
@SuppressWarnings("unchecked")
@Override
public List<Traslado> listarAtivos() {
return this.session.createQuery("SELECT t , h FROM Traslado t LEFT JOIN t.hora h WHERE t.status=:status ORDER BY t.origem , t.destino")
.setParameter("status", true)
.getResultList();
}
但我的结果是:
Hibernate: select traslado0_.TransladosID as Translad1_14_0_, trasladoho1_.TranshoraID as Transhor1_13_1_, traslado0_.tra_Para as tra_Para2_14_0_, traslado0_.tra_De as tra_De3_14_0_, traslado0_.tra_Status as tra_Stat4_14_0_, trasladoho1_.thr_qtdHoras as thr_qtdH2_13_1_, trasladoho1_.thr_TransladosID as thr_Tran3_13_1_ from tbltranslados traslado0_左外连接 tbltranshora trasladoho1_ on traslado0_.TransladosID=trasladoho1_.thr_TransladosID where traslado0_.tra_Status=?按 traslado0_.tra_De、traslado0_.tra_Para 订购 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? 休眠:选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ from tbltranshora trasladoho0_ where trasladoho0_.thr_TransladosID=? Hibernate:从 tbltranshora trasladoho0_ 中选择 trasladoho0_.TranshoraID 作为 Transhor1_13_0_,trasladoho0_.thr_qtdHoras 作为 thr_qtdH2_13_0_,trasladoho0_.thr_TransladosID 作为 thr_Tran3_13_0_ where trasladoho0_.thr_TransladosID=?
【问题讨论】:
标签: java hibernate jpa jpa-2.0