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