ClassCastException : com.agile.util.CMObjectID cannot be cast to com.agile.util.CMObjectID

Hi All,

I am using Agile PLM 9.2.2.4.
I am trying to create part using “Agile APIs” (AgileAPI.jar) through java code.
I have taken session object and have called “createObject” method of sessionObject.
Below is my code.

IAgileSession agileSession = AgileSessionFactory.createSessionEx(connectionInfoBean.getLoginInfoMap());
IAgileClass agileClass = session.getAdminInstance().getAgileClass( “Part” );
Map<IAttribute, Object> attributeMap = new HashMap<IAttribute, Object>();

//added attributes and values for Part creation in attributeMap

IDataObject dataObject = (IDataObject)session.createObject(“Part”, attributeMap);

But i am getting following exception at  line IDataObject dataObject = (IDataObject)session.createObject(“Part”, attributeMap);

Below is exception stacktrace.

java.lang.ClassCastException: com.agile.util.CMObjectID cannot be cast to com.agile.util.CMObjectID
at com.agile.apibean.APISessionBean_id91a6_EOImpl_816_WLStub.createObject(Unknown Source)
at com.agile.api.pc.Session$CreateObjectAction.doSdkAction(Session.java:1323)
at com.agile.api.common.SDKAction.run(SDKAction.java:23)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
at weblogic.security.Security.runAs(Security.java:61)
at com.agile.api.common.WebLogicAuthenticator.doAs(WebLogicAuthenticator.java:103)
at com.agile.api.common.Security.doAs(Security.java:54)
at com.agile.api.common.Security.doAs(Security.java:109)
at com.agile.api.pc.Session.createObject(Session.java:358)

Can anyone help to overcome from above problem.

Thanks & Regards,
Kulbhushan

Add Comment
2 Answer(s)

Hello

  My guess is that one of the Attribute -> value mapping is wrong and Agile is throwing this error

  Question – Does any part get created at all even though it throws this exception?

  If not, my suggestion is to split this into two to help troubleshoot the issue

1. Create the item first
2. For each of the attributes in the map, set values for this item

This will help you identify which attribute is causing this issue

Agile Angel Answered on January 30, 2019.

Hi Rchinnia,

In my case, Part is getting created successfully in Agile PLM application with below attributes.
I am creating Part with only two attributes.

1. Title Block.Number
2. Title Block.Description

But still it is throwing an exception.

on January 30, 2019.

Hi Rchinnia,

I have some findings regarding my issue.
I connect to Agile PLM system and create a session object of it.
After some time (that is after 5 minutes or more) I try to create part.
If I create new session (  IAgileSession agileSession = AgileSessionFactory.createSessionEx( myMapOfConnectionProperties ) ) to Agile PLM then it works fine. But If i don’t create new session or use the existing session object  to Agile PLM then it throws
java.lang.ClassCastException: com.agile.util.CMObjectID cannot be cast to com.agile.util.CMObjectID.

So I strongly believe the issue is regarding session and not of the data or createObject API related.
So Can I know when to create new session or how to handle the issue if I create a session and after 5 minutes i try to create part ?

Thanks & Regards,
Kulbhushan

on January 30, 2019.

So, if i understand you right, you are seeing the issue when you try to create a part 5 minutes after you create the agile session. if so, then looks like you are dealing with a stale session issue

To resolve this, you could do one of the following. Since you are in a very old version, not sure if this is supported. Give this a try

1. session.setTimeOut to 0. That means it is infinite
2. Other option is to check if the session is open before attempting to create part. Use session.isOpen(). if closed, then establish a new one

I would recommend #2

Hope this helps

on January 30, 2019.

Hi Rchinnia,
By default the session timeout value is 0 and before creating Part, session.isOpen() is also true.
So I am not able to know what is issue with old session.
Can you help regarding the above issue.

Thanks & Regards,
Kulbhushan

on January 31, 2019.

Hi Kulbhushan

 Please try splitting your calls into creating an item first and then set description. See if that works

thanks

Raj

on January 31, 2019.
Add Comment

Hi Kulbhushan,

The “Part” is pretty generic API name that is used for creation however that shouldn’t stop you from creating a part.  Also the fact that you are able to create part it means there is some issue with the Map object you have.

I used similar kind of syntax and it worked pretty fine for me:

//m_admin.getAgileClass(partType[i]).getAPIName() fetches the API name for a particular subclass.
//newAutoN : Is the AutoNumber source for my particular part type

IDataObject m_item = (IDataObject)m_session.createObject(m_admin.getAgileClass(partType[i]).getAPIName(), newAutoN);

Can you share the structure of Map you have and the attributes which you are trying to set. Also as a troubleshoot you can try to Create part fast and then set values just to isolate the issue.

Regards,
Arif

Agile Angel Answered on January 30, 2019.

Hi Arif,

I have some findings regarding my issue.
I connect to Agile PLM system and create a session object of it.
After some time (that is after 5 minutes or more) I try to create part.
If I create new session (  IAgileSession agileSession = AgileSessionFactory.createSessionEx( myMapOfConnectionProperties ) ) to Agile PLM then it works fine. But If i don’t create new session or use the existing session object  to Agile PLM then it throws
java.lang.ClassCastException: com.agile.util.CMObjectID cannot be cast to com.agile.util.CMObjectID.

So I strongly believe the issue is regarding session and not of the data or createObject API related.
So Can I know when to create new session or how to handle the issue if I create a session and after 5 minutes i try to create part ?

Thanks & Regards,
Kulbhushan

on January 30, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.