• 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

Persist is not working if after it I detach the entity

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a problem with my code, I am trying to insert some information in the database and after that detach my object.

Basically what I am doing is:



When I use that code, nothing is inserted in the database, if I remove the "em.detach(operacion)" line it is going to work.
How can I insert the information in the database and after that detach my object??
What am I doing wrong?

Thanks for in advance for your help
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try calling flush() before detaching?
 
David Acevedo
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote:Try calling flush() before detaching?



Thanks, It works now.
I have a doubt, I am doing that query 2 times every 5 seconds, in this conditions do you think "flush" can affect my application performance?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course it will affect the performance. If you have 1000 entities, you will access DB 1000 times within a single transaction.

Why do you do you detach explicitly?

After transaction is committed, entities are detached automatically. If you have 1000 entities, then there will be a single flush for all entities.

In cases more complicated that in your example there can be several flushes. But still not a flush per entity.

Try not to flush explicitly.

 
reply
    Bookmark Topic Watch Topic
  • New Topic