2015-09-23 2 views
0

Я пытаюсь сделать некоторый запрос в JPA 2, но он держит вызов другого запроса, чтобы получить informatinos из зависимостиJPA 2 - INNER JOIN вызовов запроса снова

Моих Классов:

@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; 
} 

I вызовите запрос следующим образом:

@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(); 
} 

Но мой результат:

спящий режим: выбрать traslado0_.TransladosID, как Translad1_14_0_, trasladoho1_.TranshoraID как Transhor1_13_1_, traslado0_.tra_Para как tra_Para2_14_0_, traslado0_.tra_De как tra_De3_14_0_, traslado0_.tra_Status как tra_Stat4_14_0_, trasladoho1_.thr_qtdHoras как thr_qtdH2_13_1_, trasladoho1_.thr_TransladosID как thr_Tran3_13_1_ из tbltranslados traslado0_ левого внешнего join tbltranshora trasladoho1_ on traslado0_.TransladosID = trasladoho1_.thr_TransladosID где traslado0_.tra_Status =? заказ по traslado0_.tra_De, traslado0_.tra_Para Hibernate: выберите trasladoho0_.TranshoraID в Transhor1_13_0_, trasladoho0_.thr_qtdHoras как thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID в thr_Tran3_13_0_ от tbltranshora trasladoho0_ где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =? Спящий режим: выберите trasladoho0_.TranshoraID as Transhor1_13_0_, trasladoho0_.thr_qtdHoras as thr_qtdH2_13_0_, trasladoho0_.thr_TransladosID as thr_Tran3_13_0_ от tbltranshora trasladoho0_, где trasladoho0_.thr_TransladosID =?

ответ

1

Обращайтесь к . Задайте вопрос n + 1.

Первый запрос, который вы получаете получает список вы хотите, но для того, чтобы, например, объектов сущности Traslado, Hibernate вызвать один оператор выбора для каждого объекта, чтобы выяснить, если это имеет TrasladoHora связанные, потому что отношения отображаются в TrasladoHora (я имею в виду, что TrasladoHora.traslado является стороной владельца этой двунаправленной ассоциации).

Here is a answer прокомментировал много людей с предложениями, но проблема и некоторые временное решение упомянуть в спящем документации в разделе Tuning fetch strategies

Edit: I also respond another question, связанные с этой проблемой, возможно, вы найдете более четкое объяснение там.

 Смежные вопросы

  • Нет связанных вопросов^_^