This discussion is archived
3 Replies Latest reply: Nov 20, 2012 7:24 AM by cdelahun RSS

How to get an object in the cache after register

974592 Newbie
Currently Being Moderated
Hello All,

Im trying to retrieve an object in the cache afer retgister. but ists still not working:

In the first method i have the following code
...
uow.registerNewObject(myObject);
dbCon.getActiveUnitOfWork().printRegisteredObjects(); // --> Schl³ssel: [null] Identity Hash-Code: 38596425 Objekt: com.myObject
...

in the second method.
...
Vector args = new Vector();
args.add(myArgument);
MyObject myObject= null;

// Build the query to get the last connect scrore in the cache/database
ReadObjectQuery roq = new ReadObjectQuery(MyObject.class);
roq.conformResultsInUnitOfWork();
ExpressionBuilder expBuilder = roq.getExpressionBuilder();
Expression exp = expBuilder.get("myArgument").equal(expBuilder.getParameter("myArgument"));

roq.setSelectionCriteria(exp);
roq.addArgument("myArgument");
     
MyObject = (MyObject ) dbConn.getClientSession().executeQuery(roq, args); // Still null

Thanks
  • 1. Re: How to get an object in the cache after register
    cdelahun Pro
    Currently Being Moderated
    Two things are needed for conforming to work on new object. The first is to set unitOfWork.setShouldNewObjectsBeCached(true), the second is to ensure new objects have a primary key before being registered. If you are using sequencing, you can use the unitOfWork.assignSequenceNumber(newObject) api.

    Best Regards,
    Chris
  • 2. Re: How to get an object in the cache after register
    974592 Newbie
    Currently Being Moderated
    Thanks for the reply.

    I add a sequence and assign the key bfore register the object.
    Alle registrierten Clones:
    Schl³ssel: [01-AKCA-21355792] Identity Hash-Code: 35689958 Objekt: MyObject

    But the result oft the query ist still null. I only get the object when it's already persisted.

    ReadObjectQuery roq = new ReadObjectQuery(AkcAtRatingScoreConnectScoreFull.class);
    roq.setCacheUsage(ObjectLevelReadQuery.CheckCacheThenDatabase);
    roq.conformResultsInUnitOfWork();
    roq.checkCacheByPrimaryKey();

    Regards

    Edited by: user11344339 on 20.11.2012 01:01
  • 3. Re: How to get an object in the cache after register
    cdelahun Pro
    Currently Being Moderated
    The roq.checkCacheByPrimaryKey() call overrides the roq.conformResultsInUnitOfWork() call. Try removing it and verifying that you have called setShouldNewObjectsBeCached(true) on the UnitOfWork before registering your objects.

    Best Regards,
    Chris

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points