Dear all,
I'm having a problem with a stored procedure call. Apparently, the S/P gets called, but when retrieving values from the ResultSet by column name, hibernate (or probably the Oracle Driver) looks for different column names.
In the exception below, you can see that the column name "NAME", which correctly is present in the ResultSet, is been accessed by name "NAME26_0_", thus generating a
java.sql.SQLException: Invalid column name.
Any ideas of why this is happening and how to get it working correctly?
Kind regards,
Xserty
Hibernate version:
Code:
Hibernate 3.2.1
Hibernate EntityManager 3.2.1.GA
Hibernate Annotations 3.2.1.GA
hibernate.dialect: org.hibernate.dialect.Oracle9Dialect
also tryed
hibernate.dialect: org.hibernate.dialect.OracleDialect
Mapping documents:Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="sp.SpTest" >
<id name="shipId" column="SHIP_ID" type="string">
<generator class="native"/>
</id>
<property name="name" type="string">
<column name="NAME"/>
</property>
<property name="imoNumber" type="string">
<column name="IMO_NUMBER"/>
</property>
</class>
<sql-query name="SP_TEST" callable="true">
<return alias="spTest" class="sp.SpTest">
<return-property name="shipId" column="SHIP_ID" />
<return-property name="shipName" column="NAME" />
<return-property name="shipImoNumber" column="IMO_NUMBER" />
</return>
{ call SP_TEST(?, :p_ShipID) }
</sql-query>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Query query = hibernateSession.getNamedQuery("SP_TEST");
query.setParameter("p_ShipID", pShipId);
List list = query.list();
Full stack trace of any exception that occurs:Code:
15 Dec 06 14:13:49, DEBUG org.apache.commons.logging.impl.Log4JLogger:debug:84 Transaction already joined
15 Dec 06 14:13:49, DEBUG org.apache.commons.logging.impl.Log4JLogger:debug:84 about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
15 Dec 06 14:13:49, DEBUG org.apache.commons.logging.impl.Log4JLogger:debug:84 opening JDBC connection
15 Dec 06 14:13:49, DEBUG org.apache.commons.logging.impl.Log4JLogger:debug:84
{ call SP_TEST(?, ?) }
15 Dec 06 14:13:49, DEBUG org.apache.commons.logging.impl.Log4JLogger:debug:84 bindNamedParameters() 1 -> p_ShipID [2]
15 Dec 06 14:13:49, DEBUG org.apache.commons.logging.impl.Log4JLogger:debug:84 about to open ResultSet (open ResultSets: 0, globally: 0)
15 Dec 06 14:13:49, DEBUG org.apache.commons.logging.impl.Log4JLogger:debug:84 result row: EntityKey[sp.SpTest#1]
15 Dec 06 14:13:49, INFO org.apache.commons.logging.impl.Log4JLogger:info:94 could not read column value from result set: NAME26_0_; Invalid column name
15 Dec 06 14:13:49, DEBUG org.apache.commons.logging.impl.Log4JLogger:debug:84 about to close ResultSet (open ResultSets: 1, globally: 1)
15 Dec 06 14:13:49, DEBUG org.apache.commons.logging.impl.Log4JLogger:debug:84 about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
15 Dec 06 14:13:49, DEBUG org.apache.commons.logging.impl.Log4JLogger:debug:84 aggressively releasing JDBC connection
15 Dec 06 14:13:49, DEBUG org.apache.commons.logging.impl.Log4JLogger:debug:84 releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
15 Dec 06 14:13:49, DEBUG org.apache.commons.logging.impl.Log4JLogger:debug:89 could not execute query [{ call SP_TEST(?, ?) }]
java.sql.SQLException: Invalid column name
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3291)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1914)
at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:1515)
at org.hibernate.type.StringType.get(StringType.java:18)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2046)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1371)
Name and version of the database you are using:Code:
Oracle9i Enterprise Edition Release 9.2.0.4.0
jdk1.5.0_09
jboss-4.0.5.GA
ojdbc14.jar: Implementation-Version: Oracle JDBC Driver version - 10.2.0.2.0"
The generated SQL (show_sql=true):Code:
call SP_TEST(?, ?)
Stored Procedure:Code:
PROCEDURE SP_TEST ( p_recordset OUT UTILS.type_cursor, p_ShipID IN SVD_SHIPS.SHIP_ID%TYPE ) IS
BEGIN
dbms_output.put_line ( 'START SP_TEST' );
OPEN p_recordset
FOR SELECT SVD_SHIPS.SHIP_ID,
SVD_SHIPS.NAME,
SVD_SHIPS.IMO_NUMBER
FROM SVD_SHIPS
WHERE SVD_SHIPS.SHIP_ID = p_ShipID;
dbms_output.put_line ( 'END SP_TEST' );
END SP_TEST;
Debug level Hibernate log excerpt:
Please see
Full stack trace of any exception that occurs above.