[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5518?page=c...
]
Mathias Arens commented on HHH-5518:
------------------------------------
Ok, after testing a little I found the problem. The inner join is generated because I
refer in the 'select new' to the attribute annotated with @ManyToOne:
{code:sql}
select new de.test.AlertDetail(...alert.responsibleUser) from AlertDO alert left join
alert.responsibleUser,...
{code}
Hibernate does not evaluate the from clause. If there is a reference to the @ManyToOne
reference in the select clause then it generates an inner join. It does not check if there
is an outer join in the from clause defined.
If I remove the 'alert.responsibleUser' from the select clause then I get the left
outer join without an inner join in the sql output.
In my opinion hibernate should check if an outer join is defined in the from clause before
generating an inner join. Or it should overwrite the inner join with an left outer join if
that is possible. But I don't know what the jpa spec says to it.
@ManyToOne(fetch=FetchType.LAZY) annotation generates always an inner
join into a query
---------------------------------------------------------------------------------------
Key: HHH-5518
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5518
Project: Hibernate Core
Issue Type: Bug
Components: query-hql
Affects Versions: 3.5.5
Environment: Java 1.6.0_20, Hibernate-EntityManager 3.5.5-Final, HSQLDB, Oracle
11g
Reporter: Mathias Arens
Attachments: HibernateTest.zip
Hibernate generates a left outer join *plus* a inner join for the same relation into my
query.
I have a simple @ManyToOne annotation for a reference from a alert object to a user
object:
{code}
public class Alert {
[...]
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "RESPONSIBLE_USER_ID")
private UserDO responsibleUser;
[...]
}
{code}
My jpql query is a little more complex:
{code:sql}
select rra from AlertWithResponsibleUserDO rra left join rra.responsibleUser, TeamDO t,
BusinessPartnerSearchDO bps join t.teamMembers tm where rra.businessPartnerId =
bps.businessPartnerId and (bps.ratingObjectType = 'STANDARD' or
bps.ratingObjectType is null) and bps.analyst = tm.organisationalUnit and t.id = :teamId
and rra.severity in (:severities) and bps.locale = :locale and bps.localeBpType =
:localeBpType"
{code}
The central outer join definition is this:
{code}
AlertWithResponsibleUserDO rra left join rra.responsibleUser
{code}
But Hibernate keeps creating a left outer join *and* a inner join for this relation
whatever I do:
{code:sql}
from
V440_R_ALERTS_WITH_RESP_USER alertwithr0_
left outer join
V004_USER userdo1_
on alertwithr0_.F440_F004_RESPONSIBLE_USER_ID=userdo1_.F004_ID
inner join
V004_USER userdo6_
on alertwithr0_.F440_F004_RESPONSIBLE_USER_ID=userdo6_.F004_ID cross
{code}
I already tried different queries and @ManyToOne attributes but none of them affected the
sql outcome. I tried a similar relation in a different context but there it worked.
Hibernate generated only a left outer join into the sql query. But I don't know which
settings generate the two joins on the same relation.
I have added a simple maven test project. Just unzip the HibernateTest.zip and run
'mvn test'. A starting point for further testing could be the
AppTest.testManyToOneInnerJoinIssue() test routine.
Thanks for your help in advance.
--
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