You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by "M. Walter" <ma...@sbb.ch> on 2011/08/02 16:58:39 UTC

Version of all children is incremented in OneToMany when merging parent entity

I have a OneToMany relationship defined like this:

@Entity
Parent {
    @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY, cascade = {
CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE})
    private List<Child> childList;
    // ...
    @Version
    private int version;
}

@Entity
Child {
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "PARENT_ID")
    private Parent parent;
    // ...
    @Version
    private int version;
}

Now when I change ONE of the child elements and do a merge by executing
em.merge(parent), the version of ALL children is incremented by one! I
expected that the version of the changed child is incremented only. Is this
a bug? I could not find anything about this behaviour in the
documentation...

--
View this message in context: http://openjpa.208410.n2.nabble.com/Version-of-all-children-is-incremented-in-OneToMany-when-merging-parent-entity-tp6645128p6645128.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Version of all children is incremented in OneToMany when merging parent entity

Posted by Michael Dick <mi...@gmail.com>.
Statement batching is an OpenJPA optimization. By default OpenJPA will try
to use JDBC statement batching. There's a section in the user manual at :
http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_dbsetup_stmtbatch.

Depending on the application, statement batching can provide a significant
performance boost. For example inserting several rows to the same table can
be batched, and executed in a single conversation with the database.

If your application updates several different tables, or different parts of
the same table, statement batching provides less of a benefit.

If you believe it will not benefit your app, or you want to remove the
batching from the equation, you can disable batching by adding the following
property to persistence.xml :

<property name="openjpa.jdbc.DBDictionary" value="batchLimit=0"/>

Hope this helps,
-mike

On Fri, Aug 5, 2011 at 8:27 AM, M. Walter <ma...@sbb.ch> wrote:

> Please can anyone explain to me when "batching prepstmnt" occurs? What
> exactly is the cause of this? What are the reasons causing OpenJPA to batch
> statements?
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Version-of-all-children-is-incremented-in-OneToMany-when-merging-parent-entity-tp6645128p6656525.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Re: Version of all children is incremented in OneToMany when merging parent entity

Posted by "M. Walter" <ma...@sbb.ch>.
Please can anyone explain to me when "batching prepstmnt" occurs? What
exactly is the cause of this? What are the reasons causing OpenJPA to batch
statements?

--
View this message in context: http://openjpa.208410.n2.nabble.com/Version-of-all-children-is-incremented-in-OneToMany-when-merging-parent-entity-tp6645128p6656525.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Version of all children is incremented in OneToMany when merging parent entity

Posted by Rick Curtis <cu...@gmail.com>.
> As I said before the default LockManager (version) is responsible for
incrementing the version of all children even if the objects are not
modified.

I don't know if that is the case. I know you pointed out before that the
manual states that we don't do exclusing locking, but our resource-local
unit tests show that we are updating the version fields only dirty Entities
(which makes logical sense to me).

I don't belive that you want to be running with the pessimistic lock
manager. (From the user manual)"... the
org.apache.openjpa.jdbc.kernel.PessimisticLockManager , which uses SELECT
FOR UPDATE statements (or the database's equivalent) to lock the database
rows corresponding to locked objects.

> so there has to be a difference between resource-local and JTA handling.
This is where we need to direct our investigation. I can't come up with a
reason that JTA vs resource-local would cause this issue... but I've seen
weirder things before. Perhaps collecting trace from running in the app
server will shed some light on what is going on?

On Thu, Aug 4, 2011 at 9:48 AM, M. Walter <ma...@sbb.ch> wrote:

> Hi Rick,
>
> when I run the application server, entites are loaded and converted to DTOs
> which are serialized and transported to the client via the network. Next
> the
> client changes some values (or one value in this case). Then the DTOs are
> transferred back to the server and converted into JPA entities again. A
> merge is done to persist the changes.
>
> As I said before the default LockManager (version) is responsible for
> incrementing the version of all children even if the objects are not
> modified. (I used this LockManager in my test and only the modified
> object's
> version was touched, so there has to be a difference between resource-local
> and JTA handling.) To increment all childrens' version field is a VERY
> strict behaviour of OpenJPA and in my opinion this makes not sense in every
> case. But how can I switch this off? If I set LockManager to "none" there
> is
> no difference to "version". And "pessimistic" with
> "VersionUpdateOnWriteLock" set to false or none or whatever (not documented
> what value to use to switch it off) didn't help either. So what can I do?
>

-- 
*Rick Curtis*

Re: Version of all children is incremented in OneToMany when merging parent entity

Posted by "M. Walter" <ma...@sbb.ch>.
Hi Rick,

when I run the application server, entites are loaded and converted to DTOs
which are serialized and transported to the client via the network. Next the
client changes some values (or one value in this case). Then the DTOs are
transferred back to the server and converted into JPA entities again. A
merge is done to persist the changes.

As I said before the default LockManager (version) is responsible for
incrementing the version of all children even if the objects are not
modified. (I used this LockManager in my test and only the modified object's
version was touched, so there has to be a difference between resource-local
and JTA handling.) To increment all childrens' version field is a VERY
strict behaviour of OpenJPA and in my opinion this makes not sense in every
case. But how can I switch this off? If I set LockManager to "none" there is
no difference to "version". And "pessimistic" with
"VersionUpdateOnWriteLock" set to false or none or whatever (not documented
what value to use to switch it off) didn't help either. So what can I do?

--
View this message in context: http://openjpa.208410.n2.nabble.com/Version-of-all-children-is-incremented-in-OneToMany-when-merging-parent-entity-tp6645128p6653036.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Version of all children is incremented in OneToMany when merging parent entity

Posted by Rick Curtis <cu...@gmail.com>.
> What I do NOT see in my test are those strange "batching prepstmnt" update
statements in the logs. I wonder what JPA is doing here. It looks like JPA
is stockpiling update statements for later usage. And what exactly are those
"executing batch prepstmnt" for?
I don't have a good answer for you here... Maybe someone else on the list
can chime in on this question.

I do have a few thoughts as to why you can't recreate the problem. When you
are running the application server, are your Entities being
serialized/deserialized? If so, try adding this to your test case... Just
prior to calling em.merge(...), serialize and then deserialize your
Entities. This will strip out our detached statemanager and this could
explain the behavior that you are seeing. Give it a shot and let us know how
it goes.

On Thu, Aug 4, 2011 at 8:43 AM, M. Walter <ma...@sbb.ch> wrote:

> Well I'm not able to get a test "working". :-( In the JUnit test only the
> changed child's version is increased as it should be. The main difference
> is
> that in my test I'm using resource-local transaction type with Derby
> instead
> of JTA and Oracle. OpenJPA properties in the persistence.xml files are the
> same.
>
> What I do NOT see in my test are those strange "batching prepstmnt" update
> statements in the logs. I wonder what JPA is doing here. It looks like JPA
> is stockpiling update statements for later usage. And what exactly are
> those
> "executing batch prepstmnt" for? As you can see JPA is setting the
> MUT_VERSION of all children to 28 but only child 328241 has actually
> changed
> the MUT_USER field:
>
> openjpa.jdbc.JDBC: Trace: The batch limit is set to 100.
> openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
> 2077588437 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
> 15:36:37.496, (int) 28, (long) 13260, (long) 328238, (int) 27]
> openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
> 2077588437 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
> 15:36:37.496, (int) 28, (long) 13260, (long) 328239, (int) 27]
> openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
> 2077588437 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
> 15:36:37.496, (int) 28, (long) 13260, (long) 328240, (int) 27]
> openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> executing batch
> prepstmnt 2077588437 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?,
> PARENT_ID = ? WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp)
> 2011-08-04 15:36:37.496, (int) 28, (long) 13260, (long) 328240, (int) 27]
> openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update success count
> 3
> openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
> statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ?.
> openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
> statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ?.
> openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
> statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ?.
> openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> executing
> prepstmnt
> 628303219 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_USER = ?, MUT_VERSION = ?,
> PARENT_ID = ? WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp)
> 2011-08-04 15:36:37.496, (String) JOHN, (int) 28, (long) 13260, (long)
> 328241, (int) 27]
> openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
> 904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
> 15:36:37.496, (int) 28, (long) 13260, (long) 328242, (int) 27]
> openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
> 904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
> 15:36:37.496, (int) 28, (long) 13260, (long) 328243, (int) 27]
> openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
> 904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
> 15:36:37.496, (int) 28, (long) 13260, (long) 328244, (int) 27]
> openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
> 904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
> 15:36:37.496, (int) 28, (long) 13260, (long) 328245, (int) 27]
> openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
> 904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
> 15:36:37.496, (int) 28, (long) 13260, (long) 328246, (int) 27]
> openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
> 904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
> 15:36:37.496, (int) 28, (long) 13260, (long) 328247, (int) 27]
> openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
> 904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
> 15:36:37.496, (int) 28, (long) 13260, (long) 328232, (int) 27]
> openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
> 904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
> 15:36:37.496, (int) 28, (long) 13260, (long) 328233, (int) 27]
> openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
> 904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
> 15:36:37.496, (int) 28, (long) 13260, (long) 328234, (int) 27]
> openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
> 904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
> 15:36:37.496, (int) 28, (long) 13260, (long) 328235, (int) 27]
> openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
> 904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
> 15:36:37.496, (int) 28, (long) 13260, (long) 328236, (int) 27]
> openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
> 904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
> 15:36:37.496, (int) 28, (long) 13260, (long) 328237, (int) 27]
> openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> executing batch
> prepstmnt 904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?,
> PARENT_ID = ? WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp)
> 2011-08-04 15:36:37.496, (int) 28, (long) 13260, (long) 328237, (int) 27]
> openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update success count
> 12
> openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
> statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ?.
> openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
> statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ?.
> openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
> statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ?.
> openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
> statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ?.
> openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
> statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ?.
> openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
> statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ?.
> openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
> statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ?.
> openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
> statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ?.
> openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
> statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ?.
> openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
> statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ?.
> openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
> statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ?.
> openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
> statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
> WHERE ID = ? AND CHILD.MUT_VERSION = ?.
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Version-of-all-children-is-incremented-in-OneToMany-when-merging-parent-entity-tp6645128p6652752.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>



-- 
*Rick Curtis*

Re: Version of all children is incremented in OneToMany when merging parent entity

Posted by "M. Walter" <ma...@sbb.ch>.
Well I'm not able to get a test "working". :-( In the JUnit test only the
changed child's version is increased as it should be. The main difference is
that in my test I'm using resource-local transaction type with Derby instead
of JTA and Oracle. OpenJPA properties in the persistence.xml files are the
same.

What I do NOT see in my test are those strange "batching prepstmnt" update
statements in the logs. I wonder what JPA is doing here. It looks like JPA
is stockpiling update statements for later usage. And what exactly are those
"executing batch prepstmnt" for? As you can see JPA is setting the
MUT_VERSION of all children to 28 but only child 328241 has actually changed
the MUT_USER field:

openjpa.jdbc.JDBC: Trace: The batch limit is set to 100.
openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
2077588437 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
15:36:37.496, (int) 28, (long) 13260, (long) 328238, (int) 27]
openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
2077588437 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
15:36:37.496, (int) 28, (long) 13260, (long) 328239, (int) 27]
openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
2077588437 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
15:36:37.496, (int) 28, (long) 13260, (long) 328240, (int) 27]
openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> executing batch
prepstmnt 2077588437 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?,
PARENT_ID = ? WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp)
2011-08-04 15:36:37.496, (int) 28, (long) 13260, (long) 328240, (int) 27]
openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update success count
3
openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ?.
openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ?.
openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ?.
openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> executing prepstmnt
628303219 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_USER = ?, MUT_VERSION = ?,
PARENT_ID = ? WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp)
2011-08-04 15:36:37.496, (String) JOHN, (int) 28, (long) 13260, (long)
328241, (int) 27]
openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
15:36:37.496, (int) 28, (long) 13260, (long) 328242, (int) 27]
openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
15:36:37.496, (int) 28, (long) 13260, (long) 328243, (int) 27]
openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
15:36:37.496, (int) 28, (long) 13260, (long) 328244, (int) 27]
openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
15:36:37.496, (int) 28, (long) 13260, (long) 328245, (int) 27]
openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
15:36:37.496, (int) 28, (long) 13260, (long) 328246, (int) 27]
openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
15:36:37.496, (int) 28, (long) 13260, (long) 328247, (int) 27]
openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
15:36:37.496, (int) 28, (long) 13260, (long) 328232, (int) 27]
openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
15:36:37.496, (int) 28, (long) 13260, (long) 328233, (int) 27]
openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
15:36:37.496, (int) 28, (long) 13260, (long) 328234, (int) 27]
openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
15:36:37.496, (int) 28, (long) 13260, (long) 328235, (int) 27]
openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
15:36:37.496, (int) 28, (long) 13260, (long) 328236, (int) 27]
openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> batching prepstmnt
904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp) 2011-08-04
15:36:37.496, (int) 28, (long) 13260, (long) 328237, (int) 27]
openjpa.jdbc.SQL: Trace: <t 1494112526, conn 1933144889> executing batch
prepstmnt 904345063 UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?,
PARENT_ID = ? WHERE ID = ? AND CHILD.MUT_VERSION = ? [params=(Timestamp)
2011-08-04 15:36:37.496, (int) 28, (long) 13260, (long) 328237, (int) 27]
openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update success count
12
openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ?.
openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ?.
openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ?.
openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ?.
openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ?.
openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ?.
openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ?.
openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ?.
openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ?.
openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ?.
openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ?.
openjpa.jdbc.JDBC: Trace: ExecuteBatch command returns update count -2 for
statement UPDATE CHILD SET MUT_TSTAMP = ?, MUT_VERSION = ?, PARENT_ID = ?
WHERE ID = ? AND CHILD.MUT_VERSION = ?.

--
View this message in context: http://openjpa.208410.n2.nabble.com/Version-of-all-children-is-incremented-in-OneToMany-when-merging-parent-entity-tp6645128p6652752.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Version of all children is incremented in OneToMany when merging parent entity

Posted by Michael Dick <mi...@gmail.com>.
If you're explicitly locking the entities I can see where a version update
would be appropriate. If you're just merging changes in then it's not clear
why the versions would be updated.

If you could post a testcase that would probably be the most helpful.

-mike

On Wed, Aug 3, 2011 at 10:59 AM, Rick Curtis <cu...@gmail.com> wrote:

> Yes, sorry. I noticed it after I sent my response. I don't have a lot of
> experience with OpenJPA locking, but I don't think you want to use the
> pessimistic lock manager. I'd rather get back on the track of figuring out
> why we have the behavior that we do. If you get a ut going I'll take a peek
> at it.
>
>
> On Wed, Aug 3, 2011 at 10:23 AM, M. Walter <ma...@sbb.ch> wrote:
>
> > Hi Rick,
> >
> > did you read my second posting?
> >
> > --
> >
>
>
>
> --
> *Rick Curtis*
>

Re: Version of all children is incremented in OneToMany when merging parent entity

Posted by Rick Curtis <cu...@gmail.com>.
Yes, sorry. I noticed it after I sent my response. I don't have a lot of
experience with OpenJPA locking, but I don't think you want to use the
pessimistic lock manager. I'd rather get back on the track of figuring out
why we have the behavior that we do. If you get a ut going I'll take a peek
at it.


On Wed, Aug 3, 2011 at 10:23 AM, M. Walter <ma...@sbb.ch> wrote:

> Hi Rick,
>
> did you read my second posting?
>
> --
>



-- 
*Rick Curtis*

Re: Version of all children is incremented in OneToMany when merging parent entity

Posted by "M. Walter" <ma...@sbb.ch>.
Hi Rick,

did you read my second posting?

--
View this message in context: http://openjpa.208410.n2.nabble.com/Version-of-all-children-is-incremented-in-OneToMany-when-merging-parent-entity-tp6645128p6649130.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Version of all children is incremented in OneToMany when merging parent entity

Posted by Rick Curtis <cu...@gmail.com>.
> Is this a bug? I could not find anything about this behaviour in the
documentation...
I'm not certain, but this smells of a bug to me. I couldn't find any
compelling reason why we would update all the children version fields if
they weren't dirtied. Could you perhaps come up with a unit test that shows
this behavior?

On Tue, Aug 2, 2011 at 9:58 AM, M. Walter <ma...@sbb.ch> wrote:

> I have a OneToMany relationship defined like this:
>
> @Entity
> Parent {
>    @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY, cascade = {
> CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE})
>    private List<Child> childList;
>    // ...
>    @Version
>    private int version;
> }
>
> @Entity
> Child {
>    @ManyToOne(fetch = FetchType.EAGER)
>    @JoinColumn(name = "PARENT_ID")
>    private Parent parent;
>    // ...
>    @Version
>    private int version;
> }
>
> Now when I change ONE of the child elements and do a merge by executing
> em.merge(parent), the version of ALL children is incremented by one! I
> expected that the version of the changed child is incremented only. Is this
> a bug? I could not find anything about this behaviour in the
> documentation...
>
> -
>
-- 
*Rick Curtis*

Re: Version of all children is incremented in OneToMany when merging parent entity

Posted by "M. Walter" <ma...@sbb.ch>.
Okay, reading the manual sometimes helps... ;-)

Increasing the version on all children is OpenJPA default:

/This lock manager does not perform any exclusive locking, but instead
ensures read consistency by verifying that the version of all read-locked
instances is unchanged at the end of the transaction.
Furthermore, a write lock will force an increment to the version at the end
of the transaction, even if the object is not otherwise modified. This
ensures read consistency with non-blocking behavior.

This is the default openjpa.LockManager setting in JPA.
/
This setting can be overriden by using the pessimistic lock manager and its
properties:

/The pessimistic LockManager can be configued to additionally perform the
version checking and incrementing behavior of the version lock manager
described below by setting its VersionCheckOnReadLock and
VersionUpdateOnWriteLock properties.
/
So I configured OpenJPA to not change the version on update:

<property name="openjpa.LockManager"
value="pessimistic(VersionCheckOnReadLock=true,VersionUpdateOnWriteLock=false)"
/>

But it does not work. The version fields of all children are still
incremented. Do I miss something? What do I have to configure in order to
have OpenJPA update the changed entities' version field only?

--
View this message in context: http://openjpa.208410.n2.nabble.com/Version-of-all-children-is-incremented-in-OneToMany-when-merging-parent-entity-tp6645128p6648304.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.