Skip to main content
1-Visitor
March 9, 2016
Solved

Bug while using QueryResult

  • March 9, 2016
  • 1 reply
  • 5110 views

Hello,

I have got strange exception while using wt.fc.QueryResult class. In code below it returns type [Lwt.fc.Persistable; (with symbols) instead wt.fc.Persistable

protected void collectEntrance() {

   try {

  QueryResult qr = WTPartHelper.service.getUsesWTParts(part, new LatestConfigSpec());

   while (qr.hasMoreElements()) {

  WTPart nextPart = (WTPart) qr.nextElement();

   //TODO:remove with specification element
   switch (nextPart.getPartType().toString()) {

   case "separable":

   structure.add(new Assembly(nextPart, part));

   break;

   case "detail":

   structure.add(new Detail(nextPart, part));

   break;

  }

  }

  } catch (WTException e) {

  e.printStackTrace();

  }

}

What should I do?

Thanks.

Best answer by imendiola

Hi Andrey,

if your log is giving the same error than the first time, and in the same line number (79)... Try restarting the MethodServer if you have not done.

The cast exception is because you were trying to cast a Persistable array (Persistable[]) to a Persistable object. And the method you are using (WTPartHelper.service.getUsesWTParts(part, new LatestConfigSpec()) returns a QueryResult of Persistable[]

Just to be sure, your method should look like this:

protected void collectEntrance() {

    try {

        QueryResult qr = WTPartHelper.service.getUsesWTParts(part, new LatestConfigSpec());

        while (qr.hasMoreElements()) {

            // WTPart nextPart = (WTPart) qr.nextElement();

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

            WTPart nextPart = (WTPart) aPersistable[1]; 

           

            //TODO:remove with specification element

            switch (nextPart.getPartType().toString()) {

                case "separable":

                    structure.add(new Assembly(nextPart, part));

                    break;

                case "detail":

                    structure.add(new Detail(nextPart, part));

                    break;

            }

        }

    } catch (WTException e) {

        e.printStackTrace();

    }

}

If it continues giving an error, check the line number where the error is thrown in the log.

ava.lang.ClassCastException: [Lwt.fc.Persistable; cannot be cast to wt.fc.Persistable

    at ru.windchill.versioncontrolreport.details.Element.collectEntrance(Element.java:79)

    at ru.windchill.versioncontrolreport.details.Element.<init>(Element.java:42)

Regards

1 reply

13-Aquamarine
March 9, 2016

Hi Andrey,

try with this:

while (qr.hasMoreElements()) {

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

     WTPart nextPart = (WTPart) aPersistable[1];

}

If I remember well, I think that position 0 of the array contains the UsageLink and position 1 contains the child WTPart.

Regards

atemnikov1-VisitorAuthor
1-Visitor
March 9, 2016

Hi, Iker

I have tried to do as you said, but again caught exception java.lang.ClassCastException: [Lwt.fc.Persistable; cannot be cast to wt.fc.Persistable

I think, problem is in using of reflective methods, but I cannot trace it. There is part of log:

java.lang.ClassCastException: [Lwt.fc.Persistable; cannot be cast to wt.fc.Persistable

...my methods...

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at wt.httpgw.HTTPServletResponse.invoke(HTTPServletResponse.java:251)

...others...

May it be any problems with installing or settings of Windchill?

Regards

imendiola13-AquamarineAnswer
13-Aquamarine
March 9, 2016

Hi Andrey,

if your log is giving the same error than the first time, and in the same line number (79)... Try restarting the MethodServer if you have not done.

The cast exception is because you were trying to cast a Persistable array (Persistable[]) to a Persistable object. And the method you are using (WTPartHelper.service.getUsesWTParts(part, new LatestConfigSpec()) returns a QueryResult of Persistable[]

Just to be sure, your method should look like this:

protected void collectEntrance() {

    try {

        QueryResult qr = WTPartHelper.service.getUsesWTParts(part, new LatestConfigSpec());

        while (qr.hasMoreElements()) {

            // WTPart nextPart = (WTPart) qr.nextElement();

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

            WTPart nextPart = (WTPart) aPersistable[1]; 

           

            //TODO:remove with specification element

            switch (nextPart.getPartType().toString()) {

                case "separable":

                    structure.add(new Assembly(nextPart, part));

                    break;

                case "detail":

                    structure.add(new Detail(nextPart, part));

                    break;

            }

        }

    } catch (WTException e) {

        e.printStackTrace();

    }

}

If it continues giving an error, check the line number where the error is thrown in the log.

ava.lang.ClassCastException: [Lwt.fc.Persistable; cannot be cast to wt.fc.Persistable

    at ru.windchill.versioncontrolreport.details.Element.collectEntrance(Element.java:79)

    at ru.windchill.versioncontrolreport.details.Element.<init>(Element.java:42)

Regards