1

I have developed a web app using Spring Roo (Spring MVC 3), JPA 1, Hibernate, JSTL, JQUERY etc..Persistence Contexts are application managed via a JPA Transaction manager. DB used is MSSQL2005. The application is running on JBOSS 5.

Everything works fine. My question is something that has been on my mind, yet i have yet to come across a suitable answer.

Suppose the following:

  1. I retrieve some row from Table T using entitymanager.find(), and present the data to a page
  2. I manually change one of the field values in the row (via SQL an gui tool).
  3. I immediately repeat step (1), and I have the manually updated value available.

Is this correct? My understanding was that values within the persistence context do not get updated unless:

  • calling em.refesh()
  • object is not available in PERSISTENCE CONTEXT (--> query DB instead)

My experience seems to contradict the link below, which actually makes logical sense to me.

Updated data (in Database) is not visible via JPA/Eclipselink

Many thanks

NaP

Community
  • 1
  • 1

1 Answers1

1

This is the correct behavior. The values within a persistence context won't be updated unless you call em.refresh() within a SESSION. When you retrieve the web page again, the old session is closed and a new session is opened with new data reflected.

Khue Vu
  • 3,112
  • 4
  • 37
  • 40