Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB QL - Changes with data in Table NOT REFLECTED

 
Nitin Sinha
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my scenario -

I have an Entity Bean (MyTable) -





I Have a Session Bean (MySession) -





Now, I build Entity & Session Bean in a JAR file and call them in Client file below.

AND I Have a Client File (Client.java)







Now, my problem is that when i call this method getListValues() of Client.java, it returns the result of the query specified in Session Bean but when i go and edit the table in the backend - Commit the values in the backend itself and then call this method, it fetches old values.

How Can I call em.refresh() here? Where Do i need to call em.refresh()? In the client file or Session Bean. If in the client file then how will it recognize em (EntityManager) in Client file?

Do I also need to call em.flush along with refresh ?
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


EntityManager.clear()

Clear the persistence context, causing all managed entities to become detached. Changes made to entities that have not been flushed to the database will not be persisted.


That's kind of heavy handed, so you likely want to pull the clear() call into its own method and only invoke it when necessary.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic