Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Caching or Isolations-Level Problem?
Caching or Isolations-Level Problem? [message #385301] Mon, 26 January 2009 23:19 Go to next message
Georg  is currently offline Georg Friend
Messages: 2
Registered: July 2009
Junior Member
Hello,

i'm playing around with the sample application
org.eclipse.persistence.example.jpa.employee.xml and having one hard
problem. For testing purpose i write my own test who read a List of
objects modifiing them and makes them persistent. After the commit i
change the data with another client (MySQL Querry-Browser). I'm not able
to read those external commited changes. I know this problem from jdbc. We
have to set the isolation level TRANSACTION_READ_COMMITTED to be able to
read those changes back. MySQL start by default with a harder isolation
level and supressing reading of commited Data.

I've tryed to disabled the cache in orm.xml and via annotation.
Whats wrong? Isolation level, caching, or unsing an EntityManager?


Here ist the Sample Code.

EntityManager em = getEMF().createEntityManager();
List<LargeProject> projectListPrimary;
List<LargeProject> projectListSecondary;

em.getTransaction().begin();
projectListPrimary = (List<LargeProject> ) em.createQuery("SELECT e FROM
LargeProject e").getResultList();

for ( LargeProject number : projectListPrimary ) {
number.setDescription(number.getDescription() + "-666");
em.persist(number);
}
em.getTransaction().commit();
Re: Caching or Isolations-Level Problem? [message #385307 is a reply to message #385301] Tue, 27 January 2009 13:04 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

An EntityManager represents an extended persistence context, so anything
read into an EntityManager will not be refreshed unless you explicitly
call refresh() on the object, or clear() the EntityManager. You can also
create a new EntityManager, and the life-cycle on an EntityManager
typically corresponds to one transaction or request.

EclipseLink also provides a query hint to refresh,
"eclipselink.refresh"="true".
EclipseLink also has a shared cache for the persistence unit, so anything
read can also be in the cache, and not refreshed until either explicitly
refreshed, or invalidated. To disable the EclipseLink cache set the
persistence.xml property "eclipselink.cache.shared.default"="false".

See also,
http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Using_EclipseLink_JPA_Extensions_for_Entity_Caching

and,

http://wiki.eclipse.org/Optimizing_the_EclipseLink_Applicati on_(ELUG)#Optimizing_Cache


James : Wiki : Book : Blog : Twitter
Re: Caching or Isolations-Level Problem? [message #385403 is a reply to message #385307] Tue, 27 January 2009 19:37 Go to previous messageGo to next message
Georg  is currently offline Georg Friend
Messages: 2
Registered: July 2009
Junior Member
Thanks James,

unfortunately your links directing to an empty site. I've changed my code
and using MS SQL Server to check if is an DBMS specific problem. It is the
same problem. I using you hints. As you can see i've closing the
EntityManager between the reads. Just for testing i tried to disable.

I've ssen there is a way to configure the isolation level of the
connection with an SessionCustomizer. Has anyone an idea how to do that
programmatically within a unitTest? I don't understand the docs and failed
using an session.xml.



EntityManager em = getEMF().createEntityManager();
List<LargeProject> projectListPrimary;
List<LargeProject> projectListSecondary;
// Loading Data
// Version 1 of Data
em.getTransaction().begin();
projectListPrimary = (List<LargeProject> ) em.createQuery("SELECT e FROM
LargeProject e").getResultList();


// Changing Data
// Version 2 of Data
for ( LargeProject number : projectListPrimary ) {
number.setBudget(666.66);
em.persist(number);
}
// Clear References
projectListPrimary.clear();

// Close EntityManager
em.getTransaction().commit();
em.clear();
em.close();
System.gc();

// Meanwhile CHANGING Date within another Client e.g. MySQL Querry
Browser
// Version 3 of Data

// Start new EntityManager
em = getEMF().createEntityManager();

// Try to read changed data back
// Try to read Version 3
// But getting Version 2
em.getTransaction().begin();
projectListSecondary = (List<LargeProject> ) em.createQuery("SELECT e
FROM LargeProject e").getResultList();
em.getTransaction().commit();

projectListPrimary.clear();
projectListSecondary.clear();




Here my persistence.xml:


<?xml version="1.0" encoding="windows-1252" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="employee" transaction-type="RESOURCE_LOCAL">
<description>This is part of the Employee JPA example using just XML
configuration.</description>
<properties>
<proptery name="eclipselink.cache.shared.default" value="false"/>
<property name="eclipselink.logging.level" value="FINE"/>
<property name="eclipselink.logging.thread" value="false"/>
<property name="eclipselink.logging.session" value="false"/>
<property name="eclipselink.logging.timestamp" value="false"/>
<property name="eclipselink.logging.exceptions" value="false"/>
<property name="eclipselink.jdbc.url"
value="jdbc:sqlserver://srv_mssql\produktiv;DatabaseName=GET"/>
<property name="eclipselink.jdbc.user" value="GET"/>
<property name="eclipselink.jdbc.password" value="sonne"/>
<property name="eclipselink.jdbc.driver"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="eclipselink.jdbc.read-connections.min" value="1"/>
<property name="eclipselink.jdbc.write-connections.min" value="1"/>
<property name="eclipselink.target-database" value="Auto"/>
</properties>
</persistence-unit>
</persistence>
Re: Caching or Isolations-Level Problem? [message #385407 is a reply to message #385403] Wed, 28 January 2009 13:44 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

So you are saying you do not see the changes made from the other program?
Ensure you commit the transaction on the other program, you have probably
not committed the changes.

You should be able to confirm through JDBC or any other database tool if
you can see the changes you made from the other program.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Previous Topic:JPQL and partial attributes
Next Topic:Mapping inherited id attribute
Goto Forum:
  


Current Time: Wed Nov 26 01:53:22 GMT 2014

Powered by FUDForum. Page generated in 0.02984 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software