Ahoj, asi by nebylo nezajimave zminit verzi Hibernate ...
Pokud pouzivate dotaz, pak jste schopen zapisem inner join fetch nebo outer
join fetch donutit hibernate aby to dotahla
rovnou. Chovani Hibernate je spis to nedelat a zavisle entity tahat separatnimi
dotazy, aby se dalo vyuzivat cachovani.
Takze pro vas pripad asi neco:
from Invoice as i inner join fetch i.invoiceEntries
Jirka
Martin Chalupa napsal(a):
> 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
>
--
Jiří Mareš (mailto:[EMAIL PROTECTED])
ČSAD SVT Praha, s.r.o. (http://www.svt.cz)
Czech Republic