Native SQL queries with addJoin or <return-join/> return object arrays instead of single Entities

Description

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 query.

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.

Attachments

1
  • 07 Sep 2007, 11:53 PM

Activity

Show:

Brett MeyerJanuary 7, 2015 at 4:39 PM

Closing – no test case provided and no further responses.

Brett MeyerSeptember 3, 2014 at 3:59 PM

Re-opened, but please provide a test case. Thanks!

Jahan ZinedineSeptember 3, 2014 at 3:29 PM

Seems to be an issue in hibernate 4, I'm on Grails 2.4.3 which depends on hibernate 4.3.5.5

Brett MeyerJuly 8, 2014 at 3:11 PM

Bulk rejecting stale issues. If this is still a legitimate issue on ORM 4, feel free to comment and attach a test case. I'll address responses case-by-case. Thanks!

Brett MeyerApril 7, 2014 at 5:47 PM

In an effort to clean up, in bulk, tickets that are most likely out of date, we're transitioning all ORM 3 tickets to an "Awaiting Test Case" state. Please see http://in.relation.to/Bloggers/HibernateORMJIRAPoliciesAndCleanUpTactics for more information.

If this is still a legitimate bug in ORM 4, please provide either a test case that reproduces it or enough detail (entities, mappings, snippets, etc.) to show that it still fails on 4. If nothing is received within 3 months or so, we'll be automatically closing them.

Thank you!

Out of Date

Details

Assignee

Reporter

Components

Affects versions

Priority

Created September 7, 2007 at 11:53 PM
Updated January 7, 2015 at 4:39 PM
Resolved January 7, 2015 at 4:39 PM

Flag notifications