New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FBClob doesn't implement length() method [JDBC270] #317
Comments
Commented by: Roman Rokytskyy (rrokytskyy) It is correct re. how to call the underlying FBBlob instance, but the result you get will not be precise - the average chars per byte won't work with UTF-8. That is the reason why I did not implement the method. |
Commented by: Sebastian Bösl (sboesl) I see. |
Commented by: @mrotteveel JDBC does not require this method to be implemented: http://docs.oracle.com/javase/7/docs/api/java/sql/Clob.html#length() : Maybe there are other drivers out there that do the same, so maybe it is wise to handle the exception generically |
Commented by: Pablo León (palevi) This is also causing problems with Mybatis 3.4.x (3.3.x and previous where working ok): Error querying database. Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'DIRECCION' from result set. Cause: org.firebirdsql.jdbc.FBDriverNotCapableException: Cannot determine length for CLOB |
Commented by: @mrotteveel Unfortunately it is impossible to do this correctly with UTF8 (without reading the entire blob). And as this is an optional JDBC method, you'll need to ask MyBatis if they really need this method. More curiously though, Jaybird handles a BLOB SUB_TYPE TEXT primarily as a longvarchar, and java.sql.Clob is actually just supported as a fallback; however according to https://github.com/mybatis/mybatis-3/blob/master/src/main/java/org/apache/ibatis/type/TypeHandlerRegistry.java#L91 the LONGVARCHAR handling is mapped to ClobTypeHandler, instead of the StringTypeHandler or maybe the ClobReaderTypeHandler. The ClobTypeHandler (https://github.com/mybatis/mybatis-3/blob/master/src/main/java/org/apache/ibatis/type/ClobTypeHandler.java) obtains a string using: public String getNullableResult(ResultSet rs, int columnIndex) The workaround is to configure an alternative type handler (eg the StringTypeHandler). |
Submitted by: Sebastian Bösl (sboesl)
Assigned to: Roman Rokytskyy (rrokytskyy)
Votes: 1
Hibernate 4.1 uses the FBClob.length() method when reading Clobs from the database, in the current version of Jaybird the method throws a FBDriverNotCapableException which Hibernate can't handle.
I've fixed the problem by implementing the method as follows (though I don't know if it's 100% correct:
public long length() throws SQLException {
String encoding = getWrappedBlob().gdsHelper.getJavaEncoding();
if (encoding != null) {
float bytePerChar = Charset.forName(encoding).newDecoder().averageCharsPerByte();
return (long)(getWrappedBlob().length() * bytePerChar);
}
return getWrappedBlob().length();
}
The text was updated successfully, but these errors were encountered: