[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.rt.eclipselink] Re: Cache issue

You either have a EM per request (that is what you have now) or you could consider using an EM per session. But you have to be careful with multiple requests trying to start the transaction, so one-per-request is the safest.


Enrico wrote:
I would like to add a question to my previous post.
What is the best way or mode to run eclipselink jpa on Tomcat?
Is my previous architecture (instantiate and then close a new entityManager every time I need to save/update/delete data on my local DB)?


If not, what is the best way?

BR,
Enrico

Enrico ha scritto:
Dear all,

I have a problem when I enable the eclipselink cache default one).

All my CRUD (Create, Read, Update and Delete) are implemented instantiating and closing an EntityManager. For example:

public final T findById(I id) {
EntityManager entityManager = JpaManager.getManager();
try { return (T) entityManager.find(entityClass, id); }catch(Exception ex){
....
} finally {
entityManager.close();
} return null;
}



public final void save(final T object) {

    EntityManager entityManager = JpaManager.getManager();
           try {
        entityManager.getTransaction().begin();

entityManager.persist(object);
entityManager.getTransaction().commit(); }catch(Exception ex){
entityManager.getTransaction().rollback();
......
}finally {
entityManager.close();
}
}



It happens that sometimes I save an object and then I load (e.g. findBtyId) but the retrieved value in not updated (that is, it is not the last value I have saved or updated). On the DB, the table contain the right value (the last saved).



I've tried to disable the cache in the persistence.xml file:

<property name="eclipselink.cache.type.default" value="None"/>

and all is going well.

Any help about?I need to configure the cache differently basing on the structure of my code?)

BR,
Enrico