[ 
https://issues.apache.org/jira/browse/OPENJPA-1553?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12842742#action_12842742
 ] 

Fay Wang commented on OPENJPA-1553:
-----------------------------------

The left outer join is due to the default eager fetch of the ManyToOne relation 
in Child to Parent. If you annotate this relation to be lazily fetch, the left 
outer join will be gone.

    @ManyToOne(fetch = FetchType.LAZY)
    private Parent parent;


8863  join  TRACE  [main] openjpa.jdbc.SQL - <t 9470766, conn 26506390> 
executing prepstmnt 19823722 SELECT t0.id, t0.PARENT_ID FROM Child t0 WHERE 
(t0.PARENT_ID = ?)  [params=(long) 1]
8903  join  TRACE  [main] openjpa.jdbc.SQL - <t 9470766, conn 26506390> [40 ms] 
spent


> JPQL simple Child query generates unnecessary Table Join
> --------------------------------------------------------
>
>                 Key: OPENJPA-1553
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1553
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 2.0.0-beta2
>         Environment: Java 6
>            Reporter: bernard
>         Attachments: SimpleJoin.zip
>
>
> The attached testcase demonstrates that for a basic child query, OpenJPA 
> generates SQL that contains two joined tables where only one is required.
> SELECT t0.id, t1.id FROM Child t0 LEFT OUTER JOIN Parent t1 ON t0.PARENT_ID = 
> t1.id WHERE (t0.PARENT_ID = ?)
> This creates performance issues. Please note that this is a simplified 
> testcase - performance issues are of course not present in it.
> It can be expected that JPA that provides a layer of abstraction by nature, 
> generates optimized SQL.
> In light of the fact that this is a 2.0 release, the priority of solving this 
> should be high.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to