Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.3.1
Name and version of the database you are using: Postregsq 8.2
Hello everyone. It's pretty easy question about excess fetching of data. Imagine I have two entities: Order and OrderReport. OrderReport references Order:
Code:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "order_id")
private Order order;
and this query returns orderReport objects without order object
Code:
session.createQuery("from OrderReport ").list()
OrderReport [id=1, order=Order[ id=null, field1=null]].
OrderReport2 [id=2, order=Order[ id=null, field1=null]].
Why order is not initialized by Hibernate using the foreign id of orderReport? See:
OrderReport [id=1, order=Order[ id=11, field1=null...]].
OrderReport2 [id=2, order=Order[ id=22, field1=null...]].
So, I have to write something like:
Code:
session.createQuery("select rep from OrderReport rep join fetch rep.order").list()
which fetches data from order too, allthough I don't need them, only the foreign id or, speaking in Hibernate language, orderReport.getOrder.getId(). That's all I need, but I have to make joins to find this foreign key. How can I avoid this?
Thanks in advance!