Hibernate version:
hibernate-core-3.3.1.GA
hibernate-commons-annotations-3.1.0.GA
hibernate-annotations-3.4.0.GA
Mapping documents:
None. Using annotations.
Full stack trace of any exception that occurs:
2009-01-20 13:29:26,473 ERROR pool-1-thread-1 util.JDBCExceptionReporter DB2 SQL error: SQLCODE: -302, SQLSTATE: 22001, SQLERRMC: null
2009-01-20 13:29:26,473 ERROR pool-1-thread-1 occ.DemarcateTransaction An exception occurred. Rolling back database transaction.
org.hibernate.exception.DataException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:100)
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)
at com.netgiro.occ.common.avs.AvsAnswerCodeDaoHib.getAvsAnswerCode(AvsAnswerCodeDaoHib.java:40)
<snip>
Caused by: com.ibm.db2.jcc.c.SqlException: DB2 SQL error: SQLCODE: -302, SQLSTATE: 22001, SQLERRMC: null
at com.ibm.db2.jcc.c.kh.c(kh.java:1660)
at com.ibm.db2.jcc.c.kh.a(kh.java:1224)
at com.ibm.db2.jcc.b.db.n(db.java:737)
at com.ibm.db2.jcc.b.db.i(db.java:257)
at com.ibm.db2.jcc.b.db.c(db.java:53)
at com.ibm.db2.jcc.b.t.c(t.java:46)
at com.ibm.db2.jcc.b.sb.g(sb.java:154)
at com.ibm.db2.jcc.c.kh.o(kh.java:1219)
at com.ibm.db2.jcc.c.lh.d(lh.java:2436)
at com.ibm.db2.jcc.c.lh.d(lh.java:2507)
at com.ibm.db2.jcc.c.lh.S(lh.java:432)
at com.ibm.db2.jcc.c.lh.executeQuery(lh.java:415)
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)
... 103 more
Name and version of the database you are using:
DB2 8.1.6
The generated SQL (show_sql=true):
Hibernate: select this_.AACM_RESPONSE_CODE as AACM1_4_0_, this_.AACM_ANSWER_CODE as AACM2_4_0_, this_.AACM_DESCRIPTION as AACM3_4_0_ from AVS_ANSWER_CODE_MAP this_ where this_.AACM_RESPONSE_CODE=?
Problem description
I have a DB2 database table which contains a primary key column defined as VARCHAR(2). When I try to run an hibernate query using a string larger than two I get the exception found above.
I've tested using hsqldb and it works correctly and returns an empty result.
I've also tested using hql and criteria and always get the exception when using DB2.
Code:
final Criteria crit = getSession().createCriteria(AvsAnswerCode.class);
crit.add(Restrictions.eq("iResponseCode", "123"));
return (AvsAnswerCode) crit.uniqueResult();
If I alter the column size from two to three then the criteria above works correctly and returns null.
This seems like a bug to me, but may be this is by design? Shouldn't I be able to perform an hibernate query with a string whose length is greater than the size of the db column and simply receive an empty result set back?
If this seems like a bug, let me know and I'll create the minimum code required to reproduce it.
/Scott