[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Read/write and caching
|
Hello,
The doc at
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Caching
describes caching options in EclipseLink, but the first paragraph
briefly states that EntityManagers have their own cache.
What you are hitting is that each EntityManager has its own cache
separate from the shared cache you have configured. Once an entity is
loaded into one, it keeps them isolated from seeing changes made in the
other EntityManagers, making them act like a transaction.
You should either release the EntityManager and obtain a new one on each
loop, or clear the EntityManager so that entities will be pulled from
the database or shared cache.
Best Regards,
Chris
On 15/03/2012 2:57 AM, Sebastian Weber wrote:
Hi All,
…and post again. I have some trouble with my Mail-Server and
subcribe/notification/confirm messages from the mailing list.
I hope you see this post fort he first time. Thanks in advance for you help!
I still like to setup a simple EclipseLink example with MySQL Database
and EclipseLink Caching. I found enough information about how I can
configure the cache but my Example still not working.
My Example:
Entry DBTSIRS:
@Entity
@Cache(
type=CacheType.FULL,
size=200,
expiry=10000
)
@NamedQueries({
@NamedQuery(name = "getAllIRS",
query = "SELECT e FROM DBTSIRS e",
hints = {@QueryHint(name = QueryHints.CACHE_USAGE,
value = CacheUsage.CheckCacheThenDatabase)})
})
public class DBTSIRS implements Serializable {
/** */
private static final long serialVersionUID = 3937702217098914083L;
@Id
private int irsID;
@Column(columnDefinition = "VARCHAR(50)")
private String gpslongitude;
@Column(columnDefinition = "VARCHAR(50)")
private String gpslatitude;
…
}
Thread 1 Just read from DB and print:
List<DBTSIRS> irs2 = this.em.createQuery("SELECT r from DBTSIRS r WHERE
r.irsID = 1",
DBTSIRS.class).setHint(QueryHints.CACHE_USAGE,CacheUsage.CheckCacheByPrimaryKey).getResultList();
List<DBTSIRS> irs3 = this.em.createNamedQuery("getAllIRS",
DBTSIRS.class).getResultList();
Thread 2 change the position attributes in DBTSIRS:
this.em.getTransaction().begin();
DBTSIRS dbirs = this.em.find(DBTSIRS.class, 1);
int lng = Integer.parseInt(dbirs.getGpslongitude());
int lat = Integer.parseInt(dbirs.getGpslatitude());
dbirs.setGpslatitude(Integer.toString(++lat));
dbirs.setGpslongitude(Integer.toString(++lng));
this.em.merge(dbirs);
this.em.getTransaction().commit();
So these two Threats are running each 5 seconds. Each Thread ha a
separate EntityManager generated by the EntityManagerFactory. Thread 2
is modifying the attributes. By the way String will not be the best data
type to store position information! Yes I know! Just for this test!
After the Commit the position attributes the DB show me the current
valid position information (1,2,3,4,…)
The Thread 1 still print me the first read value (1).
I guess I do something wrong on the caching configuration. The
modification don’t affect to the EntityManager cache of Thread 1.
Can you give me a hint where I can find information about this “issue”
or better what I doing wrong.
Thanks a lot!
Sebastian
--
Freundliche Grüße / Best Regards
Sebastian Weber
----------------------------------------------------------------------------------------------
Sebastian Weber, M.Sc.
Kommunikationssysteme / Communication Systems
Fakultät für Ingenieurwissenschaften / School of Engineering
Hochschule für Technik und Wirtschaft des Saarlandes (HTW) /
University of Applied Sciences
Standort / Location:
HTW Hochschul-Technologie-Zentrum (HTZ)
Campus IT-Park (CIP)
Altenkesseler Strasse 17/D2
66115 Saarbruecken, Germany
Phone: +49 681 5867-663
Mobile: n.a.
Fax: +49 681 5867-671
E-Mail: sebastian.weber@xxxxxxxxxxxxxxx
URL: http://www.htw-saarland.de
----------------------------------------------------------------------------------------------
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users