persistence@glassfish.java.net

Re: UPDATE after SELECT when executing em.find

From: James Sutherland <jamesssss_at_yahoo.com>
Date: Wed, 23 Apr 2008 06:30:57 -0700 (PDT)

That is quite odd. I assume it is related to you Properties LOB and change
tracking thinking this field value has always changed. Please confirm this
by marking the field as transient.

Since the properties is serialized, the way TopLink uses to determine if it
has changed is to serialize it and compare the bytes. So what is most
likely occurring is that the byte are changing, either because something in
your object or app is changing the value, or because the Properties does not
produce a consist serialized bytes representation. My guess would be
because Properties is a Map and hashing can be random, it is producing
different bytes each time, or more likely some of the time.

If this turns out to be the case, as a work around you could try changing
the type to something with a consistent serialization (List or LinkedHashMap
perhaps), or map the properties to another table such as using a TopLink
DirectMapMapping. Also in TopLink 11g and EclipseLink there is a mutable
setting that can be used with attribute change tracking that will track
changes differently and most likely not have this issue.


Dies wrote:
>
> Hello,
>
> I'm seeing an UPDATE after SELECT when executing em.find and I hope
> someone can help me with it.
> I want to use a @Version field with optimistic locking, but each time I
> do a find the version field is incremented.
>
> My entity has a field of type java.util.Properties, which I marked with
> @Lob.
> From my session bean I add some properties to it and persist it. That
> goes fine.
> In the next call I do an em.find in the session bean and return the
> entity instance to the client. That's all. However, when I set the
> toplink.logging.level.sql property to FINE I see that after the SELECT,
> and UPDATE is executed too.
>
> Why?
> When I add only one property, I see no UPDATE.
>
> I'm using GlassFish V2 UR1 with the Toplink Essentials that comes with
> it, the database is Oracle and the table is created using
> toplink.ddl-generation.
>
> I'm using a JTA Entity Manager. Here's my entity's source:
>
> import java.io.Serializable;
> import java.util.Properties;
>
> import javax.persistence.*;
>
> @Entity
> public class Target implements Serializable {
> private static final long serialVersionUID = 1L;
>
> @Id
> private Long id=1L;
>
> // @Version
> private int version;
>
> @Lob
> private Properties properties = new Properties();
>
> public Long getId() {
> return id;
> }
>
> public int getVersion() {
> return version;
> }
>
> public Properties getProperties() {
> return properties;
> }
>
> Thanks!
> Dies
>
>
>


-----
---
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/UPDATE-after-SELECT-when-executing-em.find-tp16827115p16834605.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.