Topic
  • 2 replies
  • Latest Post - ‏2014-11-17T16:36:37Z by isayyid
Woody_SJH
Woody_SJH
3 Posts

Pinned topic error performing object query

‏2014-01-27T23:05:35Z |

Using standalone 8.6 WebSphere eXtreme Scale

Getting this exception, does anyone know why?

Exception in thread "main" com.ibm.websphere.objectgrid.query.ObjectQueryException: A partition id or SessionHandle is required for queries to run over a partitioned map.

 

here is my code:

ObjectGridManager ogm = ObjectGridManagerFactory.getObjectGridManager();

ClientClusterContext ccc = ogm.connect("localhost:2809", null, null);

ObjectGrid grid = ogm.getObjectGrid(ccc, "FSMGrid");

BackingMap map = grid.getMap("TranslateMap");

Session session = grid.getSession();

session.begin();

ObjectMap om = session.getMap("TranslateMap");

Translate rv = (Translate)om.get("5key");

System.out.println("Found 1 translate: " + rv.translateCode);

ObjectQuery q = session.createObjectQuery("SELECT t FROM TranslateMap t WHERE t.id = ?1");

q.setParameter(1, 5L);

Iterator it = q.getResultIterator();

Translate t = (Translate) it.next();

System.out.println("Found 2 translate: " + t.translateCode);

session.commit();

 

here is my output:

[1/27/14 17:02:09:104 CST] 00000001 ObjectGridImp I CWOBJ1128I: The client cache is enabled for maps [TranslateMap] on the FSMGrid ObjectGrid.

[1/27/14 17:02:09:143 CST] 00000001 ClientDomainC I CWOBJ1126I: The ObjectGrid client connected to the FSMGrid grid in the DefaultDomain domain using connection 0.

[1/27/14 17:02:09:272 CST] 00000001 JvmMemoryUtil I CWOBJ4542I: Basic BackingMap memory size was enabled.

[1/27/14 17:02:09:305 CST] 00000001 BaseMap I CWOBJ0033I: Class, class com.mutualofomaha.model.Translate, does not implement the clone method. Using serialization instead for this Class in map TranslateMap.

Found 1 translate: 555555

Exception in thread "main" com.ibm.websphere.objectgrid.query.ObjectQueryException: A partition id or SessionHandle is required for queries to run over a partitioned map.

at com.ibm.ws.objectgrid.query.ClientObjectQueryImpl.validatePartition(ClientObjectQueryImpl.java:609)

at com.ibm.ws.objectgrid.query.ClientObjectQueryImpl.getResultMap(ClientObjectQueryImpl.java:195)

at com.ibm.ws.objectgrid.query.ClientObjectQueryImpl.getResultIterator(ClientObjectQueryImpl.java:580)

at com.mutualofomaha.app.TestApplication.main(TestApplication.java:34)

 

 

  • gvigo
    gvigo
    24 Posts

    Re: error performing object query

    ‏2014-11-17T00:08:35Z  

    Hi There,

     

    did you manage to solve this error?

    (com.ibm.websphere.objectgrid.query.ObjectQueryException: A partition id or SessionHandle is required for queries to run over a partitioned map)


    Cheers, Giovanni

  • isayyid
    isayyid
    21 Posts

    Re: error performing object query

    ‏2014-11-17T16:36:37Z  
    • gvigo
    • ‏2014-11-17T00:08:35Z

    Hi There,

     

    did you manage to solve this error?

    (com.ibm.websphere.objectgrid.query.ObjectQueryException: A partition id or SessionHandle is required for queries to run over a partitioned map)


    Cheers, Giovanni

    You need to set the partition number on the ObjectQuery to route the query too the partition

    For example:

    for (int i=0; i < totalPartitions; i++) {

         session.begin();

         ObjectQuery q = session.createObjectQuery( .... );

         q.setPartitionNumber(i);

         ....

        session.commit();

    }

    OR you can also use Session TwoPhase and set the partition number to -1 which will send the query to all partitions and merge the results back.

    session.setTxCommitProtocol(TxCommitProtocol.TWOPHASE);

    session.begin();

    ObjectQuery q = session.createObjectQuery( .... );

    q.setPartitionNumber(-1);

    session.commit();