[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2831) Native SQL queries with addJoin or <return-join/> return object arrays instead of single Entities

Chris Paulson-Ellis (JIRA) noreply at atlassian.com
Mon Mar 24 12:10:33 EDT 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2831?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_29853 ] 

Chris Paulson-Ellis commented on HHH-2831:
------------------------------------------

I have discovered another strange fact about addJoin()...

If I do a query joining related entities and call addEntity() & addJoin(), then I get back an Object[2] = { Entity, Entity } for each row, rather than the expected Object  = { Entity }. This is the problem others have encountered.

However, if I add a scalar to the query results and call addEntity(), addJoin() & addScalar(), then I get back an Object[2] = { Entity, Scalar } for each row. This is what I would expect given my reading of the purpose of addJoin(), but is inconsistent with the behavior without the scalar.

I'm using 3.2.6 GA.

Regards,
Chris.

> 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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list