Subject | DataTruncation when querying with like and % |
---|---|
Author | José Manuel Rus |
Post date | 2006-09-08T01:04:27Z |
Hi,
My problem is that 'like' queries throw DataTruncation exceptions or
produce empty results when the search text reachs the column length or
the column length -1.
I'm using Firebird 1.5.3 together with JayBird 2.0.1/2.1.0 (embedded)
and Hibernate 3.1.3, but I'm posting here because it seems to me that
this is more related to Firebird.
I have a sentence of the form:
... where fieldName like ?
Over a VARCHAR field. When I enter %value% as the parameter and value
has the column length or the column length -1 it breaks.
With JayBird 2.1.0 it produces an empty result when there
should be matches, and with JayBird 2.0.1 just throws a DataTruncation
exception:
Caused by: org.hibernate.exception.GenericJDBCException: could not
execute query
at
org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateCo\
nverter.java:103)
at
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2148)
at
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at
org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1533)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
...
Caused by: java.sql.DataTruncation: Data truncation
at
org.firebirdsql.jdbc.field.FBWorkaroundStringField.setString(FBWorkaroundStringF\
ield.java:95)
at
org.firebirdsql.jdbc.AbstractPreparedStatement.setString(AbstractPreparedStateme\
nt.java:383)
at org.hibernate.type.StringType.set(StringType.java:26)
at
org.hibernate.type.NullableType.nullSafeSet(NullableType.java:83)
at
org.hibernate.type.NullableType.nullSafeSet(NullableType.java:65)
at
org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1514)
at
org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1576)
at org.hibernate.loader.Loader.doQuery(Loader.java:661)
at
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:2\
24)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
... 16 more
Souldn't I be able to query for %value% with value entries as long as
the column length?
For the record, I built the query with Hibernate as:
Restrictions.like("fieldName", "%" + filter + "%")
or
Restrictions.like("fieldName", filter, MatchMode.ANYWHERE)
And the result is the same.
Regards.
My problem is that 'like' queries throw DataTruncation exceptions or
produce empty results when the search text reachs the column length or
the column length -1.
I'm using Firebird 1.5.3 together with JayBird 2.0.1/2.1.0 (embedded)
and Hibernate 3.1.3, but I'm posting here because it seems to me that
this is more related to Firebird.
I have a sentence of the form:
... where fieldName like ?
Over a VARCHAR field. When I enter %value% as the parameter and value
has the column length or the column length -1 it breaks.
With JayBird 2.1.0 it produces an empty result when there
should be matches, and with JayBird 2.0.1 just throws a DataTruncation
exception:
Caused by: org.hibernate.exception.GenericJDBCException: could not
execute query
at
org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateCo\
nverter.java:103)
at
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2148)
at
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at
org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1533)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
...
Caused by: java.sql.DataTruncation: Data truncation
at
org.firebirdsql.jdbc.field.FBWorkaroundStringField.setString(FBWorkaroundStringF\
ield.java:95)
at
org.firebirdsql.jdbc.AbstractPreparedStatement.setString(AbstractPreparedStateme\
nt.java:383)
at org.hibernate.type.StringType.set(StringType.java:26)
at
org.hibernate.type.NullableType.nullSafeSet(NullableType.java:83)
at
org.hibernate.type.NullableType.nullSafeSet(NullableType.java:65)
at
org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1514)
at
org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1576)
at org.hibernate.loader.Loader.doQuery(Loader.java:661)
at
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:2\
24)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
... 16 more
Souldn't I be able to query for %value% with value entries as long as
the column length?
For the record, I built the query with Hibernate as:
Restrictions.like("fieldName", "%" + filter + "%")
or
Restrictions.like("fieldName", filter, MatchMode.ANYWHERE)
And the result is the same.
Regards.