Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Stale Data Between GUIs Using EclipseLink JPA

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 want refreshed.

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
orm.xml.

I would recommend you continue working with JPA, and not use the native API
or Mapping Workbench.


MikeyL wrote:
> 
> 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.
> 
> MikeyL
> 


-----
---
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/Stale-Data-Between-GUIs-Using-EclipseLink-JPA-tp21353727p21417041.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top