Hello,
I have the following problem with a Hibernate Criteria-Search and Restrictsions.in() on a Table with a composite-id.
I want to retrieve entities by their composite-key-class as follows:
Code:
//QcpProcessId represents the composite-id on three columns
QcpProcessId process1 = new QcpProcessId("A 75171", new BigDecimal(0), "0201");
QcpProcessId process2 = new QcpProcessId("A 75171", new BigDecimal(5), "test");
QcpProcessId[] ids = new QcpProcessId[] { process1, process2 };
Criteria criteria = session.createCriteria(QcpProcess.class);
criteria.add(Restrictions.in(QcpProcess.PROP_ID, ids));
List list = criteria.list();
The result is this stacktrace
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2231)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
at org.hibernate.loader.Loader.list(Loader.java:2120)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
Caused by: java.sql.SQLException: ORA-01722: invalid number
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1120)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1145)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:962)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1242)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3415)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3459)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2228)
The generated SQL-Query is this:
Code:
select
this_.PLAN_ID as PLAN1_67_0_,
this_.REVISION as REVISION67_0_,
this_.PROCESS_ID as PROCESS3_67_0_,
this_.REVNOTE as REVNOTE67_0_,
this_.NOTICE as NOTICE67_0_,
this_.ORDERNO as ORDERNO67_0_,
from
QCP_PROCESS this_
where
(
this_.PLAN_ID, this_.REVISION, this_.PROCESS_ID
) in (
(
?, ?, ?
), (
?, ?, ?
)
)
When i execute this query directly on the DB, there is no error.
If I just put one id in the in-clause, regardless of which, the query works fine:
Code:
//QcpProcessId represents the composite-id on three columns
QcpProcessId process1 = new QcpProcessId("A 75171", new BigDecimal(0), "0201");
QcpProcessId[] ids = new QcpProcessId[] { process1 };
Criteria criteria = session.createCriteria(QcpProcess.class);
criteria.add(Restrictions.in(QcpProcess.PROP_ID, ids));
List list = criteria.list();
So i guess, that the mapping is ok:
Code:
<hibernate-mapping>
<class name="com.xy.db.QcpProcess" table="QCP_PROCESS">
<composite-id name="id" class="com.xy.db.QcpProcessId">
<key-property name="planId" type="java.lang.String">
<column name="PLAN_ID" length="16" />
</key-property>
<key-property name="revision" type="java.math.BigDecimal">
<column name="REVISION" />
</key-property>
<key-property name="processId" type="java.lang.String">
<column name="PROCESS_ID" length="16" />
</key-property>
</composite-id>
<property name="revnote" type="java.lang.String">
<column name="REVNOTE" length="128" />
</property>
<property name="notice" type="java.lang.String">
<column name="NOTICE" length="2048" />
</property>
<property name="orderno" type="java.math.BigDecimal">
<column name="ORDERNO" />
</property>
</class>
</hibernate-mapping>
Hibernate version is 3.3.1, DB is Oracle 10.
Could anyone please give me a hint?
Thank you in advance,
Rudi