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.
Was this topic helpful?
Document Information
Modified date:
16 June 2018
UID
swg21969388