Search in sources :

Example 1 with NoIdentityMap

use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.NoIdentityMap in project eclipselink by eclipse-ee4j.

the class EntityManagerJUnitTestSuite method testRefreshEntityWithoutCache.

public void testRefreshEntityWithoutCache() {
    EntityManager em = createEntityManager();
    NoIdentityMap map = new NoIdentityMap();
    map.setName("bob");
    beginTransaction(em);
    em.persist(map);
    commitTransaction(em);
    if (!isOnServer()) {
        closeEntityManager(em);
        em = createEntityManager();
    }
    clearCache();
    beginTransaction(em);
    Query query = em.createQuery("Select e from NoIdentityMap e where e.name = 'bob'");
    NoIdentityMap emp = (NoIdentityMap) query.getSingleResult();
    int version = emp.getVersion();
    query.setHint(QueryHints.REFRESH, true);
    emp = (NoIdentityMap) query.getSingleResult();
    commitTransaction(em);
    if (!isOnServer()) {
        closeEntityManager(em);
        em = createEntityManager();
    }
    beginTransaction(em);
    em.remove(em.find(NoIdentityMap.class, map.getID()));
    commitTransaction(em);
    if (!isOnServer()) {
        closeEntityManager(em);
    }
    assertEquals("Unchanged employee had version changed after refresh", version, emp.getVersion());
}
Also used : EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) Query(jakarta.persistence.Query) JpaQuery(org.eclipse.persistence.jpa.JpaQuery) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ObjectLevelReadQuery(org.eclipse.persistence.queries.ObjectLevelReadQuery) DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) NoIdentityMap(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.NoIdentityMap)

Aggregations

EntityManager (jakarta.persistence.EntityManager)1 Query (jakarta.persistence.Query)1 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)1 JpaQuery (org.eclipse.persistence.jpa.JpaQuery)1 DatabaseQuery (org.eclipse.persistence.queries.DatabaseQuery)1 ObjectLevelReadQuery (org.eclipse.persistence.queries.ObjectLevelReadQuery)1 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)1 NoIdentityMap (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.NoIdentityMap)1