[
https://issues.apache.org/jira/browse/OPENJPA-2680?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Wouter van der Kamp updated OPENJPA-2680:
-----------------------------------------
Attachment: jpa-test.zip
> 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 uploaded test code.
> Test.test1() does a merge() on a new object with a @GeneratedValue id. Here
> OpenJPA sends this query to the database:
> SELECT t0.name FROM Country t0 WHERE t0.id = ? [params=(long) 0]
> 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:
> 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]
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)