RE: [eclipselink-users] Stale Data Between GUIs Using EclipseLink JPA
Thanks for the reply, James.
I read a message in a newsgroup that recommended getting a new
EntityManager for every database operation and closing it right after
the operation. I also surrounded any updates, inserts, and deletes with
transactions and commits. Seems to work now.
I am rather disappointed in the performance of EclipseLink. I have
another version of the same application using native SQL (ResultSet,
PreparedStatement, etc.). It is much faster. EclipseLink makes the
coding easier, but there is a price to pay.
[mailto:eclipselink-users-bounces@xxxxxxxxxxx] On Behalf Of James
Sent: Monday, January 12, 2009 10:58 AM
Subject: Re: [eclipselink-users] Stale Data Between GUIs Using
In JPA an EntityManager represents an extended persistence context, in
that any object read into the EntityManager will remain until you either
close() or clear() the EntityManager. You can also call refresh() on an
object to refresh it explicitly. An EntityManager normally relates to a
single transaction or request. So to see changes made in another
EntityManager, or another machine, you need to either create a new
EntityManager, or clear() the existing one, or refresh() each object you
EclipseLink also managed a 2nd level shared cache at the
EntityManagerFactory level. This cache also caches the objects that are
read, so if you want fresh data you must also ensure this cache is
refreshed. Calling refresh() will also refresh the cache (unless you
have flushed changes), the cache also has invalidation API and
configuration, or can be disabled using persistence.xml
"eclipselink.cache.shared.default"="false", or the @Cache annotation or
I would recommend you continue working with JPA, and not use the native
API or Mapping Workbench.
> I am playing with a Movie-Actor application to learn about
> persistence. I have a Derby database with a Movies table with title,
> rating, release year, etc., and an Actors table with name, birth date,
> etc. I have an associative table joining a many-to-many relationship
> between Movies and Actors. The associative table declares foreign key
> fields with references back to the parent tables. I designed Swing
> GUIs to display the data. The Movie GUI will display actors for a
> selected movie in a child table. The Actor GUI will display movies for
> a selected actor in a child table. The Entity Manager Factory and
> Entity Manager are instantiated once by the main GUI at program start.
> The Movie and Actor DAOs get the Entity Manager from the main screen.
> The problem is that changes made in one GUIs do not get reflected in
> the other. E.g., if I add the movie 2 Days in the Valley to actress
> Charlize Theron in the Actor GUI then click on 2 Days in the Valley in
> the Movie GUI, Charlize is not listed as an actor in the child table.
> Even pressing the Refresh button to reload the Movie table does not
help. How do I synchronize the data between the two GUIs?
> In an attempt to solve the above problem, I took a look at EclipseLink
> Sessions. It seems that I could have the main GUI invoke a server
> session and have separate client sessions for the Movie and Actor
> GUIs. However, when using Workbench to create entity source files from
> my database tables the many-to-many relationship is not picked up by
> Workbench although the foreign key reference constraints are on the
> associative table. I crawled all over the User's Guide and can't find
> how to manually define these relationships in the mapping XML file. Is
this a bug in Workbench?
> Any help and thoughts will be appreciated.
EclipseLink , http://www.oracle.com/technology/products/ias/toplink/
Wiki: http://wiki.eclipse.org/EclipseLink EclipseLink ,
Forums: http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,
Book: http://en.wikibooks.org/wiki/Java_Persistence Java Persistence
View this message in context:
Sent from the EclipseLink - Users mailing list archive at Nabble.com.
eclipselink-users mailing list