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

Romain Manni-Bucau commented on OPENJPA-2680:
---------------------------------------------

Hi [~woutervdk],

Am I understanding right you call merge() instead of persist()? If so the 
behavior is the expected one since you are supposed to merge the entity state 
(from the select) with passed one. Note that the behavior for this case is not 
well defined by the spec but the usage of persist for that case is quite clear 
however.

> entityManager.merge() sends unnecessary select statements to the database 
> --------------------------------------------------------------------------
>
>                 Key: OPENJPA-2680
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2680
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 2.4.1
>            Reporter: Wouter van der Kamp
>         Attachments: jpa-test.zip
>
>
> See attachment jpa-test.zip.
> Test.test1() does a merge() on a new object with a @GeneratedValue id. Here 
> OpenJPA sends this query to the database:
> {code:sql}
> SELECT t0.name FROM Country t0 WHERE t0.id = ? [params=(long) 0]
> {code}
> Presumably to check whether the entity is already present in the database, 
> but this is unnecessary because it's a new object without an id (id == null). 
> Workaround for this bug is to use persist() in stead of merge(). But this is 
> not always possible, for example when using an object which is not known by 
> the EntityManager. This is Test.test2(), where OpenJPA sends the queries:
> {code:sql}
> SELECT t1.id, t1.name, t0.name FROM Citizen t0 LEFT OUTER JOIN Country t1 ON 
> t0.countryId = t1.id WHERE t0.id = ? [params=(long) 0]
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to