Bug #78961 Can't call MySQL procedure with InOut parameters in Fabric environment
Submitted: 26 Oct 2015 8:35 Modified: 2 Dec 2015 3:25
Reporter: 優 藤原 Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:5.1.37 OS:Any
Assigned to: Filipe Silva CPU Architecture:Any
Tags: fabric, InOut parameters

[26 Oct 2015 8:35] 優 藤原
Description:
When I call a stored procedure with InOut parameter, i always get exception like "java.lang.ClassCastException: com.sun.proxy.$Proxy58 cannot be cast to com.mysql.jdbc.PreparedStatement". Here is stacktrace that i captured:

java.lang.ClassCastException: com.sun.proxy.$Proxy58 cannot be cast to com.mysql.jdbc.PreparedStatement
	at com.mysql.jdbc.CallableStatement.setInOutParamsOnServer(CallableStatement.java:2014) ~[mysql-connector-java-5.1.37.jar:5.1.37]
	at com.mysql.jdbc.CallableStatement.execute(CallableStatement.java:820) ~[mysql-connector-java-5.1.37.jar:5.1.37]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_11]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_11]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_11]
	at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_11]
	at com.mysql.jdbc.MultiHostConnectionProxy$JdbcInterfaceProxy.invoke(MultiHostConnectionProxy.java:91) ~[mysql-connector-java-5.1.37.jar:5.1.37]
	at com.sun.proxy.$Proxy59.execute(Unknown Source) ~[na:na]
	at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172) ~[commons-dbcp-1.4.jar:1.4]
	at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172) ~[commons-dbcp-1.4.jar:1.4]
	at org.hibernate.result.internal.OutputsImpl.<init>(OutputsImpl.java:69) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
	at org.hibernate.procedure.internal.ProcedureOutputsImpl.<init>(ProcedureOutputsImpl.java:49) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
	at org.hibernate.procedure.internal.ProcedureCallImpl.buildOutputs(ProcedureCallImpl.java:426) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
	at org.hibernate.procedure.internal.ProcedureCallImpl.getOutputs(ProcedureCallImpl.java:378) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
	at org.hibernate.jpa.internal.StoredProcedureQueryImpl.outputs(StoredProcedureQueryImpl.java:251) ~[hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
	at org.hibernate.jpa.internal.StoredProcedureQueryImpl.execute(StoredProcedureQueryImpl.java:234) ~[hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]

How to repeat:
Call a stored procedure which contains atleast one INOUT parameter on Fabric environment.
[26 Oct 2015 10:45] Filipe Silva
Hi,

Thank you for this bug report. Verified by code review.
[27 Oct 2015 2:29] 優 藤原
Hi Filipe Silva,

We have been working for migrating some our projects to Fabric environment so this bug has great influence to us because almost our business logic is being processed inside stored procedure. 

If possible, can you please tell us a workaround solution? And when do you plan to provide a fix patch for it?

Thanks so much!
[27 Oct 2015 11:37] Filipe Silva
Hi,

I understand your urgency on this but, unfortunately, there is no known workaround for this issue.
I'm sorry, I can't give you any dates for a fix. What I can say is that we are setting this issue a very high priority.

Thank you,
[28 Oct 2015 2:05] 優 藤原
Hi Filipe Silva,

Thank you so much for your supporting!
[2 Dec 2015 3:25] Daniel So
Added the following entry to the Connector/J 5.1.38 changelog:

"In a Fabric environment, a ClassCastException resulted when a stored procedure was called with an INOUT parameter. This was because in this situation, what was being cast was a proxied version of the object. This fix extracts the underlying object from its proxy, allowing it to be cast to the implementing class."