Dobrý den, ladím rychlost hibernatu při načítání provázaných entit a narazil
jsem na následující věc. Mám tyto entity.
@Entity
@NamedQueries({
@NamedQuery(name = "Invoice.all", query = "from Invoice"),
@NamedQuery(name = "Invoice.allFetch", query = "select distinct i from
Invoice as i left join fetch i.invoiceEntries")
})
public class Invoice {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Basic
private Date created;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "invoice)
@Fetch(FetchMode.JOIN)
private Set<InvoiceEntry> invoiceEntries;
}
@Entity
public class InvoiceEntry {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Basic
private String name;
@ManyToOne
@JoinColumn(name="INVOICE_FK")
private Invoice invoice;
}
Volám tento dotaz:
sessionFactory.getCurrentSession().getNamedQuery("Invoice.all").list();
V této konfiguraci bych očekával v logu jeden provedený dotaz který bude
obsahovat join, ale je tam toto:
Hibernate: select invoice0_.id as id0_, invoice0_.created as created0_ from
Invoice invoice0_
Hibernate: select invoiceent0_.INVOICE_FK as INVOICE3_1_, invoiceent0_.id as
id1_, invoiceent0_.id as id1_0_, invoiceent0_.INVOICE_FK as INVOICE3_1_0_,
invoiceent0_.name as name1_0_ from InvoiceEntry invoiceent0_ where
invoiceent0_.INVOICE_FK=?
Hibernate: select invoiceent0_.INVOICE_FK as INVOICE3_1_, invoiceent0_.id as
id1_, invoiceent0_.id as id1_0_, invoiceent0_.INVOICE_FK as INVOICE3_1_0_,
invoiceent0_.name as name1_0_ from InvoiceEntry invoiceent0_ where
invoiceent0_.INVOICE_FK=?
Hibernate: select invoiceent0_.INVOICE_FK as INVOICE3_1_, invoiceent0_.id as
id1_, invoiceent0_.id as id1_0_, invoiceent0_.INVOICE_FK as INVOICE3_1_0_,
invoiceent0_.name as name1_0_ from InvoiceEntry invoiceent0_ where
invoiceent0_.INVOICE_FK=?
Tušíte někdo kde by mohl být problém? Nebo je toto chování normální?
Předem děkuji za odpověď.
Martin Chalupa