openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shelley <randomshel...@gmail.com>
Subject Re: @PreUpdate always called?
Date Wed, 05 Dec 2007 21:17:53 GMT

I am seeing a similar issue with OpenJPA unnecessarily calling an UPDATE on
every commit.

It appears that on every commit(), all of my entity's Date fields
(TemporalType.TIMESTAMP) are being updated even though they have not
changed.

UPDATE MY_ENTITY SET timeField = ?, version = ? WHERE id = ? AND version = ?
[params=(Timestamp) 2007-12-05 15:08:18.927, (int) 2, (int) 50, (int) 1]

My current workaround is to clear the persistence context after each commit,
but this obviously is not desirable and shouldn't be necessary.  Any ideas
as to why this might be occurring, or how to prevent it?  I am using the
majority of default OpenJPA properties (version LockManager, optimistic
locking, etc), although I have attempted to modify some of these properties
to prevent this problem, so far with no success.


Marc Siegel wrote:
> 
> Hi Patrick,
> 
> Thanks for your response.
> 
> As I mentioned in the FetchType.LAZY thread, I am using:
>   - java 1.5
>   - field access
>   - no build-time enhancement
>   - no javaagent commandline
>   - maven to build
> 
> Eagerly (or lazily?) awaiting your advice on a more stable setup for
> using OpenJPA 1.0 in either thread!
> 
> Regards,
> -Marc
> 
> 
> On 11/1/07, Patrick Linskey <plinskey@gmail.com> wrote:
>> How are you deploying your app (JDK version, are you using an appserver,
>> etc.)?
>>
>> Are you running the OpenJPA enhancer?
>>
>> -Patrick
>>
>> On Nov 1, 2007 12:20 PM, Marc Siegel <marc.siegel.17@gmail.com> wrote:
>> > Sure, the object model consists of two classes.
>> > GaAccount has OneToMany with GaCampaign, which reciprocally has
>> > ManyToOne with it.
>> >
>> > Here's how I am testing the problem:
>> >
>> > em.getTransaction().begin();
>> >         //Query query = em.createQuery("SELECT a from GaAccount a
>> > WHERE :clientEmail = a.clientEmail");
>> >         Query query = em.createQuery("SELECT a from GaAccount a LEFT
>> > JOIN FETCH a.gaCampaigns WHERE :clientEmail = a.clientEmail");
>> >         query.setParameter("clientEmail", "me@email.com");
>> >         GaAccount gaAccount = (GaAccount) query.getSingleResult();
>> >         Collection<GaCampaign> gaCampaigns =
>> gaAccount.getGaCampaigns();
>> >         int numCampaigns = gaCampaigns.size();
>> > em.getTransaction().commit();
>> >
>> > As you can see
>> >   1.  I can't get the LAZY fetch to work as advertised - I must use
>> > LEFT JOIN FETCH to retrieve the collection. Why?
>> >   2.  SQL=TRACE reveals that all objects created from the query were
>> > then updated with an UPDATE statement at the commit() line. Why?
>> >
>> > For example:
>> > 4629  com.leadgenllc.lib  TRACE  [main] openjpa.jdbc.SQL - <t 8310256,
>> > conn 164819> executing prepstmnt 5717555 UPDATE GaCampaign SET
>> > createdAt = ?, updatedAt = ?, isChanged = ?, synchronizedAt = ?,
>> > dailyBudget = ?, endDay = ?, googleId = ?, name = ?, startDay = ?,
>> > status = ?, gaAccountId = ? WHERE id = ? [params=(Timestamp)
>> > 2007-11-01 14:20:29.85, (Timestamp) 2007-11-01 15:18:51.286, (int) 0,
>> > (Timestamp) 2007-11-01 14:20:31.107, (long) 250000, (Date) 2007-10-11,
>> > (int) 23096971, (String) Campaign (B) [001], (Date) 2007-10-08,
>> > (String) Deleted, (long) 10, (long) 175]
>> >
>> > Thanks in advance,
>> > -Marc
>> >
>> >
>> >
>> > On 11/1/07, Patrick Linskey <plinskey@gmail.com> wrote:
>> > > That should not be happening; can you describe your object model in
>> > > more detail? How are you deploying your app?
>> > >
>> > > -Patrick
>> > >
>> > > On Nov 1, 2007 11:21 AM, Marc Siegel <marc.siegel.17@gmail.com>
>> wrote:
>> > > > Hi Folks,
>> > > >
>> > > > When I was using JBoss, I used @PreUpdate methods to record the
>> time
>> > > > of last modification for many entities.
>> > > >
>> > > > Using OpenJPA with SQL=TRACE, it appears that all entities that are
>> > > > queried during a transaction are committed at the end of that
>> > > > transaction, even if not modified. This is a problem for me because
>> > > > the @PreUpdate is being called and updating the modification time,
>> > > > when in truth no modifications were made, only queries.
>> > > >
>> > > > Can anyone shed any light on this problem?
>> > > >
>> > > > Thanks in advance,
>> > > > -Marc
>> > > >
>> > >
>> > >
>> > >
>> > > --
>> > > Patrick Linskey
>> > > 202 669 5907
>> > >
>> >
>>
>>
>>
>> --
>> Patrick Linskey
>> 202 669 5907
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/%40PreUpdate-always-called--tf4733240.html#a14180794
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message