• 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

JPA and multiple JVMs - refresh problems

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have two application which point to same database but run under different JVM.

1. Admin application - The admin application is responsible for adding some entites, reporting....., runs under Tomcat6.
2. Service application - The service application does some processing, running outside Tomcat6.

There is table called as DTR, when a new DTR is added through the Service application and when someone does the reporting through the Admin application, the newly added DTR does not showup. I think it only shows up the data that had been cached earlier by admin application.


Is there anyone who has faced similar problem in past or anyone who has any solution


Regards,
Faiz.
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Faiz, you're asking some great questions. I was just wondering if you could do a quick update to your name to align it with the JavaRanch naming policy? We'd sure appreciate it!

JavaRanch Naming Policy

Thanks so much!

-Cameron McKenzie
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What JPA provider are you using? How have you configured caching?
Are you using a single EntityManager, or do you create new EntityManager's per request?

In JPA you can refresh an object using EntityManager.refresh().

Any Query will normally go to the database and return any new objects. If you are accessing the objects through a relationship, then if you have caching enabled, and had previously read the object (or even if you don't have caching enabled, and are using the same EntityManager), then you could get a cached object, and its relationship would not include the newly added objects.

See also,
http://en.wikibooks.org/wiki/Java_Persistence/Caching
 
Faiz A Chachiya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Sutherland wrote:
What JPA provider are you using?
Hibernate

How have you configured caching?
I have not configured for any caching. I think the First Level Cache is default.

Are you using a single EntityManager, or do you create new EntityManager's per request?
I am using SessionFactory to create hibernate session and not using the EntityManager.

In JPA you can refresh an object using EntityManager.refresh().
I have tried session.refresh(object), but it does not help, i still get the old data.

Any Query will normally go to the database and return any new objects. If you are accessing the objects through a relationship, then if you have caching enabled, and had previously read the object (or even if you don't have caching enabled, and are using the same EntityManager), then you could get a cached object, and its relationship would not include the newly added objects.

Do i have to enable second level caching to fix the issue.


See also,
http://en.wikibooks.org/wiki/Java_Persistence/Caching





Thanks.
 
Faiz A Chachiya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried the following code



and now it updates the cache with the latest data
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Faiz A Chachiya wrote:
I have two application which point to same database but run under different JVM.

1. Admin application - The admin application is responsible for adding some entites, reporting....., runs under Tomcat6.
2. Service application - The service application does some processing, running outside Tomcat6.

There is table called as DTR, when a new DTR is added through the Service application and when someone does the reporting through the Admin application, the newly added DTR does not showup. I think it only shows up the data that had been cached earlier by admin application.


Is there anyone who has faced similar problem in past or anyone who has any solution


Regards,
Faiz.



Hello all!

We have a similar problem but we are using OpenJPA and not Hibernate.
We do a search by ID using an EntityManager object. The application worked fine when it was deployed on a single JVM server, but when it was deployed to another server that has 3 JVM's the data we retrieve by doing a search by ID is not the latest data available in the DB (so if the user changes that data via the UI and the data is stored in the DB what we retrieve when we want to fetch the data by ID is not what the user has just set but the older version).
We did not set any type of caching in the persistence.xml file. Do you have any idea what could be wrong here?

Thank you
Best regards,
Sorin
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic