Hi All,

I have created a simple test application which uses a stored procedure
to insert a record into a database using hibernate. I used hibernate
annotations and have overridden insert statement by

@SQLInsert(callable=true, sql="{? = call insert_party(?, ?, ?, ?)}", check=ResultCheckStyle.PARAM)

However, hibernate throws the exception
...
Caused by: org.hibernate.exception.GenericJDBCException: could not extract row counts from CallableStatement at org.hibernate.jdbc.Expectations$BasicParamExpectation.determineRowCount(Expectations.java:123) at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:41) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2251) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2661) at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
       at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
       at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
       at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:516)
       ... 50 more
Caused by: org.postgresql.util.PSQLException: Parameter of type java.sql.Types=2 was registered, but call to getInt (sqltype=java.sql.Types=4) was made. at org.postgresql.jdbc2.AbstractJdbc2Statement.checkIndex(AbstractJdbc2Statement.java:2387) at org.postgresql.jdbc2.AbstractJdbc2Statement.getInt(AbstractJdbc2Statement.java:1920) at org.hibernate.jdbc.Expectations$BasicParamExpectation.determineRowCount(Expectations.java:119)
       ... 62 more

I studied JDBC3 specification whether PostgreSQL driver is wrong
or not and I think that the driver is correct. There is a conversion table
on page B-182 which should correspond to ResultSet object getter
methods only. There is nothing about the conversion being done
in CallableStatement's getter methods.

Attached is the patch agains hibernate core Branch_3_2 which fixes the issue using
getBigDecimal(parameterPosition).intValue()

Please, could someone review the fix and apply the patch? Could you also back port the fix? Thank you.

Regards

Julius Stroffek
Index: src/org/hibernate/jdbc/Expectations.java
===================================================================
--- src/org/hibernate/jdbc/Expectations.java	(revision 14203)
+++ src/org/hibernate/jdbc/Expectations.java	(working copy)
@@ -8,6 +8,7 @@
 import org.hibernate.util.JDBCExceptionReporter;
 import org.hibernate.exception.GenericJDBCException;
 
+import java.math.BigDecimal;
 import java.sql.CallableStatement;
 import java.sql.SQLException;
 import java.sql.PreparedStatement;
@@ -116,7 +117,7 @@
 
 		protected int determineRowCount(int reportedRowCount, PreparedStatement statement) {
 			try {
-				return toCallableStatement( statement ).getInt( parameterPosition );
+				return toCallableStatement( statement ).getBigDecimal( parameterPosition ).intValue();
 			}
 			catch( SQLException sqle ) {
 				JDBCExceptionReporter.logExceptions( sqle, "could not extract row counts from CallableStatement" );
_______________________________________________
hibernate-dev mailing list
hibernate-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/hibernate-dev

Reply via email to