Wrong type detection for sql type char(x) columns
Description
Attachments
is duplicated by
relates to
Activity

Brett Meyer March 7, 2014 at 10:09 PM
Bulk closing tickets resolved in released versions

Strong Liu October 13, 2011 at 12:07 PM

Ufuk Cemen August 17, 2010 at 10:27 PM
Tried Bart Vanhaute's work around :
"I have found the following workaround for native queries:
instead of
select val from table
do
select cast(val as char) from table"
it didn't work but :
" select cast(val as varchar) from table "
works fine , because the issue already hibernate assumes the value is a char not a string.

KrashanK March 4, 2010 at 5:15 PM
Hi
It still doesn't work correctly (without patch) on jboss-5.1.0.GA with Hibernate 3.3.1.GA.
Native queries on temporary tables called from manager.createNativeQuery returns single Character instead String

Julien Kronegg August 7, 2009 at 3:23 PM
A cleaner workaround is to define a new Dialect:
public class DialectHhh2304 extends DB2390Dialect {
public DialectHhh2304() {
super();
// workaround for http://opensource.atlassian.com/projects/hibernate/browse/HHH-2304
registerHibernateType( Types.CHAR,1, Hibernate.CHARACTER.getName() );
registerHibernateType( Types.CHAR,255, Hibernate.STRING.getName() );
}
}
Then to use instead of the original dialect (e.g. in the persistence.xml file).
I think defining a new dialect is safer than using "char(xxx as char)" (I did not test it BTW).
When executing a sql query which returns columns of sql type char, a java.lang.Character is returned. This leads to returning just the first character of the value. In my eyes a String should be returned when the char type has a width > 1. I wasn't able to determine whether this is a jdbc driver issue or a hibernate issue. When using sql type char for columns of entities no such problems occur.
Test case is attached.