• Post Reply Bookmark Topic Watch Topic
  • New Topic

Issue with JPS and refreshing Entity bean's data.  RSS feed

 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys
I was just wondering if someone could explain what seems like an obvious issue to me, but something I'm finding very hard to get around.
If I goto the page displaying the value for 'name' I get the expected result, however if the value is changed in the database and I move
away from the page and back again, I still get the
original value, not the updated value.
Whilst debugging my code, I can see that it goes into the .getUser(int userId) method in the Service again,
so I'd expect it to get the ;atest data from the database but it doesn't. I've tried _em.refresh(userDao) but get an error about the
Entity not being managed even if I add @ManagedBean("userDao") to the Entity bean,
and I've tried _em.clear() but still I get the original data.

Here is the test code....

Service:


Entity


Controller


Thanks in advance
 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Added note:

I've seen that it does actually appear to be working, but there is a delay in the Entity bean picking up the new data! If I navigate away then straight back, I get the original data but if I wait for TWO MINUTES! then navigate away/back, it works! What's that all about, why is there this delay, surely this should be something that happens on access not on access (eventually).
 
Vishwanath Krishnamurthi
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You are caching the entity with @Cache. So I think you might have been given the cached value. That should explain why the value was stale.

HTH,
Vishwa
 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vishwanath Krishnamurthi wrote:Hi,

You are caching the entity with @Cache. So I think you might have been given the cached value. That should explain why the value was stale.

HTH,
Vishwa


D'OH!
That'll teach me. I really should spend a little more time reading what all the annotations are for!
Daft thing is I've used these annotations before but not the @Cache one, so it should have stood out to me.

Googled "@Cache (usage=CacheConcurrencyStrategy.TRANSACTIONAL)" first result that comes back:-

We also annotate the classes with the @Cache annotation to indicate that the values should be cached
@Entity
@Cache (usage=CacheConcurrencyStrategy.TRANSACTIONAL)
This defines that Customer and Contact should be cached. Any attempt to look up Customer or Contact by their primary key, will first attempt to read the entry from the cache. If it cannot be found it will load it up from the database.


Cheers for that
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!