Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hello,
I am facing an error when trying to cast version reference to Object Reference. The error is -
java.lang.ClassCastException: class wt.vc.VersionReference cannot be cast to class wt.fc.ObjectReference (wt.vc.VersionReference and wt.fc.ObjectReference are in unnamed module of loader 'app')
The code is-
String oid = (String) request.getParameter("oid");
final ReferenceFactory refFactory = new ReferenceFactory();
final ObjectReference reportRef = (ObjectReference) refFactory.getReference(oid);
Kindly suggest on how to resolve this,
Thanks
Solved! Go to Solution.
Hi @RK_10805837
You can not do that.
You need to crate new ObjectReference and assign the object to it.
Or rewrite the method you want to use.
ObjectReference objectReference = new ObjectReference();
objectReference.setObject((Persistable) reportRef.getObject());
objectReference.setKey(reportRef.getKey());
PS>it is not simple as I mentioned. The key from VersionReference can not be used in the ObjectReference object. You should build the key from the object that is used in the VersionReference.
Usually something like OR:wt.part.WTPart:105412210
PetrH
Hi @RK_10805837
The getReference method returns VersionReference object so you should work with that type class
final VersionReference reportRef = (VersionReference ) refFactory.getReference(oid);
PetrH
Hi @HelesicPetr ,
The oid passed is already of the type VersionReference. I need to cast it to ObjectReference because I have to pass it to a different method.
Can you please suggest some alternate way?
Thanks
Hi @RK_10805837
You can not do that.
You need to crate new ObjectReference and assign the object to it.
Or rewrite the method you want to use.
ObjectReference objectReference = new ObjectReference();
objectReference.setObject((Persistable) reportRef.getObject());
objectReference.setKey(reportRef.getKey());
PS>it is not simple as I mentioned. The key from VersionReference can not be used in the ObjectReference object. You should build the key from the object that is used in the VersionReference.
Usually something like OR:wt.part.WTPart:105412210
PetrH