[ 
https://issues.apache.org/jira/browse/OPENJPA-2680?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Richard Zowalla resolved OPENJPA-2680.
--------------------------------------
    Resolution: Fixed

Already fixed on master: 67c6a78eb (OPENJPA-2952, on master) makes 
BrokerImpl.isDetached skip the store find when generated PK fields still hold 
their default value (BrokerImpl.java:4941-4946, 4990-4995). 
VersionAttachStrategy.java:85 uses this check for merge. Closing; please reopen 
if this still happens with OpenJPA 4.x.

> 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
>            Priority: Major
>         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 query:
> {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
(v10.3.26#10030026)

Reply via email to