Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » UpdateAllQuery does not seem to execute
UpdateAllQuery does not seem to execute [message #385292] Thu, 22 January 2009 20:27 Go to next message
David J Rericha is currently offline David J RerichaFriend
Messages: 13
Registered: July 2009
Junior Member
Dear Newsgroup members:

I am trying to execute the UpdateAllQuery below in a 2-tiered application:

public static void updatePatients( EntityManager em )
{
UpdateAllQuery updateQuery = new UpdateAllQuery( Patient.class );
ExpressionBuilder builder = updateQuery.getExpressionBuilder();
updateQuery.setSelectionCriteria( builder.get( "lastName" ).equal(
"Smith" ) );
updateQuery.addUpdate( "lastName", "Jones" );
( (JpaEntityManager)em.getDelegate()
).getActiveSession().executeQuery( updateQuery );
}

However, no sql is logged ( I am using LogLevel.FINE ) and the database
remains unchanged. Is there something I am missing?

Thanks,


David
Re: UpdateAllQuery does not seem to execute [message #385293 is a reply to message #385292] Thu, 22 January 2009 20:56 Go to previous messageGo to next message
David J Rericha is currently offline David J RerichaFriend
Messages: 13
Registered: July 2009
Junior Member
Same for DeleteAllQuery:

public static void deletePatients( EntityManager em )
{
DeleteAllQuery query = new DeleteAllQuery( Patient.class );
ExpressionBuilder builder = query.getExpressionBuilder();
query.setSelectionCriteria( builder.get( "lastName" ).equal( "Smith" )
);
JpaEntityManager jpaEm = (JpaEntityManager)em.getDelegate();
jpaEm.getActiveSession( em ).executeQuery( query );
}
Re: UpdateAllQuery does not seem to execute [message #385294 is a reply to message #385293] Fri, 23 January 2009 04:41 Go to previous messageGo to next message
Doug Clarke is currently offline Doug ClarkeFriend
Messages: 155
Registered: July 2009
Senior Member
Have you tried using JPA's approach to bulk update/delete. I use those
queries you have shown when coding to our native API but when using JPA I
prefer the JP QL appoach.

em.createQuery("DELETE FROM Employee e WHERE e.firstName LIKE
'D%'").executeUpdate();

Doug
Re: UpdateAllQuery does not seem to execute [message #385300 is a reply to message #385293] Mon, 26 January 2009 15:20 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

The issue is that through the native API the query is deferred to the
commit by default. To have the query execute immediately use:

query.setShouldDeferExecutionInUOW(false);

----
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Re: UpdateAllQuery does not seem to execute [message #385402 is a reply to message #385300] Tue, 27 January 2009 17:12 Go to previous messageGo to next message
David J Rericha is currently offline David J RerichaFriend
Messages: 13
Registered: July 2009
Junior Member
Thank you, Doug and James for your response. The JPQL approach to bulk
updates/deletes works fine. In the UpdateAllQuery I tried the
query.setShouldDeferExecutionInUOW(false), and the update statement was
executed but did not commit. Is there something else I need to do to get
the native API approach to work?

Thanks,


David
Re: UpdateAllQuery does not seem to execute [message #385406 is a reply to message #385402] Wed, 28 January 2009 13:34 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Not sure what you mean by was executed, but did not commit. It should not
commit until you commit the transaction.

Ensure you begin/commit a JPA transaction around the query execution.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Re: UpdateAllQuery does not seem to execute [message #385411 is a reply to message #385406] Fri, 30 January 2009 00:21 Go to previous message
David J Rericha is currently offline David J RerichaFriend
Messages: 13
Registered: July 2009
Junior Member
I neglected to wrap the update/delete in a transaction. Both the
native-api and jpa methods work fine.
Previous Topic:JDK 1.4?
Next Topic:OneToMany associations
Goto Forum:
  


Current Time: Thu Mar 28 18:31:25 GMT 2024

Powered by FUDForum. Page generated in 0.04091 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top