If you are a beginer to JSF and JPA,sometimes, you may wonder why your web page does not reflect the database table values accurately, especially when the table values were modified externally.(Manually).
This happens, because when you (by default) fetch data using JPA entity manager, the values are fetched from the Entity Cache. So basically when you update the database table externally, the Entity Cache needs to be updated as well.
To get over this issue, simply,
fetch the data like this:
e = (Employee)em.createQuery("SELECT e FROM Employee e WHERE e.id = :id")
.setHint("toplink.pessimistic-lock", "Lock")
.setParameter("id", primaryKey)
.getSingleResult();
http://weblogs.java.net/blog/guruwons/archive/2006/09/understanding_t.html
No comments:
Post a Comment