• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How EntityManager flush

 
Greenhorn
Posts: 17
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have an application using JPA. When I use EntityManager and createNamedQuery and fire a getResult on this I see a weird behavior
Sometimes EntityManager's flush take lot of time to execute. Wanted to understand why this is so? What is happening under-the-hood?
Regards,
Harsha
 
Ranch Hand
Posts: 553
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By default in JPA a flush() is triggered before any query execution. This is done to ensure the database reflects any changes made so it return the correct query results.

flush has to determine if any managed objects changed, and then write these changes to the database, so depending on how many managed objects and changes, this can take a while.

Normally a flush is not required, and sometimes even not desired, so it is best to turn it off using the EntityManager or Query setFlushMode() API.

See,
http://en.wikibooks.org/wiki/Java_Persistence/Querying#Flush_Mode

In EclipseLink you can disable the auto flush entirely using the persistence unit property,

"eclipselink.persistence-context.flush-mode"="COMMIT"
 
Harsha Hegde
Greenhorn
Posts: 17
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks a lot, it worked, there has been significant improvement in the performance
Regards,
Harsha
 
Harsha Hegde
Greenhorn
Posts: 17
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi James,
Followup to the above post, i also tried the Query.setFlushMode(). The performance improvement seem to be better than EntityManager.setFlushMode() what could be the reason?
Regards,
harsha
 
Are you okay? You look a little big. Maybe this tiny ad will help:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic