weffen
weffen

Reputation: 13

Geode/Gemfire OQL's return data is incorrect in transaction view

Hello, I inserted a new entry to a region, and queried an OQL (SELECT * FROM /some_region_name) both within the same transaction, and I found that the new inserted entry was not returned in the OQL result. Dose anyone know what was going on with it?

Here are my testing codes:

    ClientCache cache = (ClientCache) EcnSpringContext.getBean("gemfireCache");

    Region<String, RUserEntity> userRegion = (Region<String, RUserEntity>) EcnSpringContext.getBean("r_user");

    CacheTransactionManager txmgr = cache.getCacheTransactionManager();
    EcnGeodeTemplate ecnGeodeTemplate = (EcnGeodeTemplate) EcnSpringContext.getBean("rUserTemplate");

    String username = "forrest";
    System.out.println("Transaction begin.");
    txmgr.begin();

    System.out.println("checking username[" + username + "] before added.");
    RUserEntity found = (RUserEntity) userRegion.selectValue("SELECT * FROM /r_user WHERE username = '" + username + "'");
    if (found == null)
        System.out.println("rUserEntity NOT found");
    else
        System.out.println("rUserEntity  found");


    RUserEntity rUserEntity = new RUserEntity();
    rUserEntity.setUsername("forrest");
    rUserEntity.setId(username);
    userRegion.put(username, rUserEntity);

    System.out.println("checking username[" + username + "] after added.");
    found = (RUserEntity) userRegion.selectValue("SELECT * FROM /r_user WHERE username = '" + username + "'");
    if (found == null)
        System.out.println("rUserEntity NOT found");
    else
        System.out.println("rUserEntity  found");


    txmgr.commit();
    System.out.println("Transaction end.");

    System.out.println("checking username[" + username + "] after transaction.");
    found = (RUserEntity) userRegion.selectValue("SELECT * FROM /r_user WHERE username = '" + username + "'");
    if (found == null)
        System.out.println("rUserEntity NOT found");
    else
        System.out.println("rUserEntity  found");

I expected the result:

Transaction begin.
checking username[forrest] before added.
rUserEntity NOT found
checking username[forrest] after added.
**rUserEntity found**
Transaction end.
checking username[forrest] after transaction.
rUserEntity  found

But unfortunately I got this result:

Transaction begin.
checking username[forrest] before added.
rUserEntity NOT found
checking username[forrest] after added.
**rUserEntity NOT found**
Transaction end.
checking username[forrest] after transaction.
rUserEntity  found

Upvotes: 0

Views: 57

Answers (1)

Swapnil
Swapnil

Reputation: 1301

This is a known limitation. From the docs:

Queries and indexes reflect the cache contents and ignore the changes  
 made by ongoing transactions. If you do a query from inside a transaction, 
the query does not reflect the changes made inside that transaction.

Upvotes: 1

Related Questions