cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

object query exception

SOLVED
Highlighted

object query exception

Hi!

I want to query PromotionTarget objects by two parameters:

String str = obj.toString();

  HashMap<String, String> objSpec = getObjSpec(str);

  QuerySpec qs = new QuerySpec(PromotionTarget.class);

  qs.setAdvancedQueryEnabled (true);

  SearchCondition sc1 = new SearchCondition(PromotionTarget.class, "roleBObjectRef.key.classname", SearchCondition.EQUAL, objSpec.get("objClass"));

  qs.appendWhere(sc1, new int[]{0});

  qs.appendAnd();

  SearchCondition sc2 = new SearchCondition(PromotionTarget.class, "roleBObjectRef.key.id", SearchCondition.EQUAL, Long.getLong(objSpec.get("objId")));

  qs.appendWhere(sc2, new int[]{0});

  QueryResult qr =  PersistenceHelper.manager.find(qs);

  Persistable[] per = null;

  while (qr.hasMoreElements())

  {

  per = (Persistable[])qr.nextElement();

  list.add((PromotionTarget)per[0]);

  }

But I have an exception like this:

wt.pom.DatastoreException: Ошибка SQL при выполнении инструкции "SELECT 'wt.maturity.PromotionTarget',A0.createLCTemplateIsNull,A0.classnamekeyA6,A0.idA3A6,A0.createState,A0.description,A0.classnamekeyroleAObjectRef,A0.idA3A5,A0.classnamekeyroleBObjectRef,A0.idA3B5,CONVERT(varchar,A0.createStampA2,120),A0.markForDeleteA2,CONVERT(varchar,A0.modifyStampA2,120),A0.idA2A2,A0.updateCountA2,CONVERT(varchar,A0.updateStampA2,120) FROM PromotionTarget A0 WHERE ((A0.classnamekeyroleBObjectRef = ?) AND (A0.idA3B5 = )) AND (A0.markForDeleteA2 = 0); Bind Parameters=[wt.doc.WTDocument]". Сообщение системы базы данных:

2015-11-13 16:31:16,075 INFO  [ajp-bio-8010-exec-4] wt.system.out nadmin - Вложенное исключение: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near ')'.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: object query exception

This code working fine:

try

  {

  String str = obj.toString();

  QuerySpec qs = new QuerySpec(PromotionTarget.class);

  qs.setAdvancedQueryEnabled (true);

  SearchCondition sc1 = new SearchCondition(PromotionTarget.class, "roleBObjectRef.key.classname", SearchCondition.EQUAL, getObjClass(str));

  qs.appendWhere(sc1, new int[]{0});

  qs.appendAnd();

  SearchCondition sc2 = new SearchCondition(PromotionTarget.class, "roleBObjectRef.key.id", SearchCondition.EQUAL, PersistenceHelper.getObjectIdentifier(obj).getId());

  qs.appendWhere(sc2, new int[]{0});

  QueryResult qr =  PersistenceHelper.manager.find(qs);

  PromotionTarget per = null;

  while (qr.hasMoreElements())

  {

  per = (PromotionTarget)qr.nextElement();

  list.add(per);

  }

  }

  catch (QueryException e) {e.printStackTrace();}

  catch (WTException e) {e.printStackTrace();}

3 REPLIES 3

Re: object query exception

This code working fine:

try

  {

  String str = obj.toString();

  QuerySpec qs = new QuerySpec(PromotionTarget.class);

  qs.setAdvancedQueryEnabled (true);

  SearchCondition sc1 = new SearchCondition(PromotionTarget.class, "roleBObjectRef.key.classname", SearchCondition.EQUAL, getObjClass(str));

  qs.appendWhere(sc1, new int[]{0});

  qs.appendAnd();

  SearchCondition sc2 = new SearchCondition(PromotionTarget.class, "roleBObjectRef.key.id", SearchCondition.EQUAL, PersistenceHelper.getObjectIdentifier(obj).getId());

  qs.appendWhere(sc2, new int[]{0});

  QueryResult qr =  PersistenceHelper.manager.find(qs);

  PromotionTarget per = null;

  while (qr.hasMoreElements())

  {

  per = (PromotionTarget)qr.nextElement();

  list.add(per);

  }

  }

  catch (QueryException e) {e.printStackTrace();}

  catch (WTException e) {e.printStackTrace();}

Re: object query exception

Hi Anton,

I guess your code was failing to get the value of long. I have seen instances where Long.getLong returns null and the logs indicates the same, there is only one parameter passed to the query. You can try Long.parseLong instead in your code to get it working.

Regards,

Bhushan

Re: object query exception

Hi Bhushan!

Thank's for your reply! I'll check it later.