Hello. I'm executing a call to a Stored Procedure. Everythings ok when I map the result entity
to standard java types like int or String. When I map many-to-one relations, everything is also ok. The problem is that the mapping of the entity must state an ID. If the ID is of standard type, no problem. When I try to use as an ID the same column I use for a many-to-one relation, it occurs the below exception. No matter if I use <composite-id> with or without <key-many-to-one>, the problem occurs the same.
I tried to debug Hib code, but the only thing I notice is that it has something to do with aliases (DefaultEntityAliases) and then I got a headache.
Sorry for some spanish mixed down there.
the code of my ar.com.tota.sop.sp.SPTest.testSP:
List result = HibernateUtil.currentTotaSession().getNamedQuery("temp_SP")
.setParameter("concesionario", 1)
.list();
Hibernate version:3.x I tried 3.0.5 and 3.2.5
[b]Mapping documents:
the StoredProcedure mapping:
<sql-query name="temp_SP" callable="true">
<return alias="res" class="ar.com.tota.sop.sp.ConsultaConsolidadaRetorno">
<return-property name="concesionario" column="id_concesionario"/>
<return-property name="lineaDeNegocio" column="id_linea"/>
<return-property name="estado" column="id_estado"/>
<return-property name="cantidad" column="cantidad"/>
</return>
{ call temp_sp1(:concesionario) }
</sql-query>
the entity mapping:
<class name="ConsultaConsolidadaRetorno">
<!-- <id name="cantidad" type="int" column="cantidad"/> -->
<id type="int" column="id_concesionario"/>
<many-to-one name="concesionario"
class="ar.com.tota.sop.entidades.ConcesionarioTota"
cascade="none"
outer-join="false"
update="false"
insert="false"
access="property"
column="id_concesionario"/>
<many-to-one
name="lineaDeNegocio"
class="ar.com.tota.sop.enums.LineaDeNegocio"
cascade="none"
outer-join="false"
update="false"
insert="false"
access="property"
column="id_linea"/>
<many-to-one
name="estado"
class="ar.com.tota.sop.enums.EstadoSolicitud"
cascade="none"
outer-join="false"
update="false"
insert="false"
access="property"
column="id_estado"/>
<property name="cantidad" type="int" insert="false" update="false"></property>
</class>
Full stack trace of any exception that occurs:
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2223)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at ar.com.tota.sop.sp.SPTest.testSP(SPTest.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.sql.SQLException: S0022: 'id1_29_0_' es un nombre de columna incorrecto. (incorrect column name)
at com.sybase.jdbc2.jdbc.ErrorMessage.raiseError(ErrorMessage.java:534)
at com.sybase.jdbc2.tds.TdsResultSet.findColumnByLabel(TdsResultSet.java:535)
at com.sybase.jdbc2.jdbc.SybResultSet.findColumn(SybResultSet.java:538)
at com.sybase.jdbc2.jdbc.SybResultSet.getInt(SybResultSet.java:349)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.getInt(NewProxyResultSet.java:2677)
at org.hibernate.type.IntegerType.get(IntegerType.java:28)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)
at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1097)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:565)
at org.hibernate.loader.Loader.doQuery(Loader.java:701)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
... 23 more
Name and version of the database you are using:
SyBase 12.5.2
INFO level Hibernate log excerpt:
INFO [UpdateTimestampsCache] starting update timestamps cache at region: org.hibernate.cache.UpdateTimestampsCache
INFO [StandardQueryCache] starting query cache at region: org.hibernate.cache.StandardQueryCache
Hibernate: { call temp_sp1(?) }
INFO [IntegerType] could not read column value from result set: id1_29_0_; S0022: 'id1_29_0_' es un nombre de columna incorrecto.
ERROR [JDBCExceptionReporter] S0022: 'id1_29_0_' es un nombre de columna incorrecto.
|