I get old data with JPA even if I disable the cache. I think this is because the resource is set to RESOURCE_LOCAL, but I'm not sure.
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/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_2_0.xsd"> <persistence-unit name="AppPU" transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <class>com.myentities.User</class> <properties> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/mydatabase"/> <property name="javax.persistence.jdbc.password" value="*****"/> <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> <property name="javax.persistence.jdbc.user" value="user1"/> <property name="eclipselink.logging.level" value="FINEST"/> </properties> </persistence-unit> </persistence>
My code that gets old user information:
public List<User> findAll(App app) { getEntityManager().getTransaction().begin(); Query q = getEntityManager().createQuery("SELECT t1 FROM User t1 WHERE t1.app.idApp=:idApp"); q.setParameter("idApp", app.getIdApp()); getEntityManager().flush(); getEntityManager().getTransaction().commit(); List resultList = q.getResultList(); return resultList; }
My essence:
@Entity @Table(name = "user") @Cache ( type=CacheType.NONE ) public class User implements Serializable {
Does anyone know what is going on?
UPDATE 1
The start, flush and fix methods were just despair! I know this is not necessary.
I forgot to say something important : the test I am doing is adding a direct user entry to the database console , and then try to view it through my webapp, which is not showing a new user . This is the "old data" that I mentioned, it displays only the "old users".
I already tried putting this on persistence.xml and I did not see any difference in the results:
<property name="eclipselink.cache.shared.default" value="false"/> <property name="eclipselink.cache.size.default" value="0"/> <property name="eclipselink.cache.type.default" value="None"/>
So something else and hellip;
source share