File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes JPA and multiple JVMs - refresh problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA and multiple JVMs - refresh problems" Watch "JPA and multiple JVMs - refresh problems" New topic
Author

JPA and multiple JVMs - refresh problems

Faiz A Chachiya
Greenhorn

Joined: Jun 05, 2007
Posts: 12

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.
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

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
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
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


TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Faiz A Chachiya
Greenhorn

Joined: Jun 05, 2007
Posts: 12
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

Joined: Jun 05, 2007
Posts: 12
I tried the following code



and now it updates the cache with the latest data
Sorin Ciolofan
Greenhorn

Joined: Feb 07, 2011
Posts: 17
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
 
wood burning stoves
 
subject: JPA and multiple JVMs - refresh problems
 
Similar Threads
Restarting Tomcat service on a remote machine from Hudson
bulk emails
where can I find the admin package of Tomcat6 ?
JSp - Servlet - Tomcat/GlassFish
Tomcat 6 Setup/configuration