Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » UpdateAllQuery does not seem to execute
UpdateAllQuery does not seem to execute [message #385292] Thu, 22 January 2009 15:27 Go to next message
Eclipse UserFriend
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 15:56 Go to previous messageGo to next message
Eclipse UserFriend
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] Thu, 22 January 2009 23:41 Go to previous messageGo to next message
Eclipse UserFriend
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 10:20 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: UpdateAllQuery does not seem to execute [message #385402 is a reply to message #385300] Tue, 27 January 2009 12:12 Go to previous messageGo to next message
Eclipse UserFriend
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 08:34 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: UpdateAllQuery does not seem to execute [message #385411 is a reply to message #385406] Thu, 29 January 2009 19:21 Go to previous message
Eclipse UserFriend
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: Fri Jul 25 21:00:36 EDT 2025

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

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

Back to the top