IBM Support

ClassCast Exception during typeCasting YFSEnvironment to YFSContext or YFSConnectionHolder

Troubleshooting


Problem

Attempts to create DB connection in a custom java code throws classCast Exception in Sterling Selling and FulFillment Suite.

Symptom

Create a DB connection in a custom java code by typecasting YFSEnvironment object to YFSContext and then use getConnection method to get the connection object; java code. This throws a classCast Exception as shown below:
java.sql.Connection con = ((YFSContext) env).getDBConnection();
is throwing below exception :
java.lang.ClassCastException: com.yantra.interop.client.InteropEnvStub  cannot be cast to com.yantra.shared.ycp.YFSContext
-------------

Connection con = ((YFSConnectionHolder) env).getDBConnection();
throws below exception :
java.lang.ClassCastException: com.yantra.interop.client.InteropEnvStub   cannot be cast to com.yantra.yfs.japi.YFSConnectionHolder

Resolving The Problem

You can extract the DB connection from the YFSEnvironment that is derived from Sterling instance only.

  • When YFSEnvironment is derived from sterling Instance : It's Env class type is of class : class com.yantra.yfs.core.YFSContext  

  • When YFSEnvironment created using YIFApi.createEnvironment : It's Env class type is of class : class com.yantra.interop.client.InteropEnvStub.

  • Class com.yantra.yfs.core.YFSContext supports getDBConnection but class com.yantra.interop.client.InteropEnvStub doesn't supports getDBConnection.

So, in custom code, you need to extract the DB connection from the YFSEnvironment that is derived from Sterling instance class com.yantra.yfs.core.YFSContext.

[{"Product":{"code":"SS6PEW","label":"IBM Sterling Order Management"},"Business Unit":{"code":"BU048","label":"IBM Software"},"Component":"--","Platform":[{"code":"PF033","label":"Windows"}],"Version":"9.2.1","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Document Information

Modified date:
16 June 2018

UID

swg21969388