[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2831?page=c...
]
Christian Merenda commented on HHH-2831:
----------------------------------------
Sorry - I accidentally hit the wrong button...
public class Person
{
int id;
Set<String> names;
}
In the database you end up with two tables:
- "person" with the field "id"
- "person_names" with the fields "id" and "name"
Now I want to use native SQL to do the following query.
SELECT person.id AS {p.id}, person_names.name AS {p.names}
FROM person LEFT OUTER JOIN person_names USING (id)
The SQL query result would be
1 - christian
1 - paolo
2 - stefano
2 - marco
When I make the following call... createSQLQuery(sql).addEntity("p",
Person.class)
... I would expect to retrieve two objects
(1, [christian,paolo])
(2, [stefano,marco])
Actually this does not work - and obviously addJoin will also not help because there's
actually no other entity joined... Is there a solution for this available?
Thanks for your help!
Christian
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