[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2831?page=c...
]
Jeremy Grodberg commented on HHH-2831:
--------------------------------------
Max Rydahl Andersen wrote : this is just how it was done initially....addJoin both eager
fetch and return the result.
Max, I'm not sure what you are saying. Are you saying it was intended for addJoin to
behave like addEntity for associated objects or rather that it wasn't fully thought
out?
How is addJoin (supposed to be) different than addEntity? It seem like now all it does is
let you specify the entity class by referring to a property rather than naming the class
explicitly, which is not nearly as useful as being able to turn on or off eager fetching
in my externalized named SQL queries without having to dive into the Java code to change
the handling of the list that the query returns. (In my case I had to turn it on to avoid
a massive N+1 selects problem when an association was added to the root entity.)
In HQL queries I can eagerly fetch an association by using LEFT JOIN FETCH and the
associated objects are not returned directly in the query results; the result is a list of
root entities. It sure looks from the documentation like addJoin was meant to be
analogous for SQL queries and it sure would be helpful to have an analog of LEFT JOIN
FETCH for SQL queries.
So, if you are saying that the behavior I see is the design intention for addJoin and
<return-join/> then please change the "component" of this issue from
query-sql to documentation and clarify the documentation of these features to indicate
that eager fetching this way WILL return the associated objects directly as well as in the
properties of the root entity and I will file a separate enhancement request to provide
for SQL queries an analog of LEFT JOIN FETCH.
However, I'd really prefer it if you did not return the associated entities fetched
with addJoin directly, since I can already get the entities returned if I want that by
using addEntity.
Native SQL queries with addJoin or <return-join/> return object
arrays instead of single Entities
-------------------------------------------------------------------------------------------------
Key: HHH-2831
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2831
Project: Hibernate3
Issue Type: Bug
Components: query-sql
Affects Versions: 3.2.4, 3.2.5
Environment: Hibernate 3.2.4.ga and 3.2.5.ga with hsqldb on Win XP
Reporter: Jeremy Grodberg
Attachments: NativeSQLQueriesTest.patch
Although the documentation is not crystal clear, I read it to say that using addJoin
should eagerly fetch an associated object but should NOT return it as a separate value.
In section 16.1.3. "Handling associations and collections" of the online
documentation it says: "It is possible to eagerly join in the Dog to avoid the
possible extra roundtrip for initializing the proxy. This is done via the addJoin()
method, which allows you to join in an association or collection." This comes BEFORE
the section on returning multiple entities, so I say the documentation at least implies it
will only return a single entity at the top level. Also, if the intention is to return
multiple entities, addEntity() works fine for that, so what then would be the difference
of addJoin()? If I'm wrong about what addJoin() should do, please clarify that in the
documentation and also clarify how, if it is possible, one could eagerly fetch the
association without changing the return type of the qu
ery.
I have reproduced this problem in the Hibernate JUnit tests in
3.2.4.ga and 3.2.5.ga, specifically NativeSQLQueriesTest.testSQLQueryInterface().
I'm attaching a patch to the Hibernate junit test
org.hibernate.test.sql.hand.query.NativeSQLQueriesTest.java released in 3.2.5.ga that adds
a test to ensure that a query with addJoin only returns a (list of) entities, not a list
of Object arrays containing entities. Currently, the assertion fails because instead of
returning a list of Organizations we get a list of Object[3] = { Organization, Employment,
Person }, which is exactly what we get when the addJoin()s are replaced with appropriate
addEntity() calls.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira