Wrong type detection for sql type char(x) columns

Description

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.

Environment

Hibernate 3.2.0, Oracle 9.2, Oracle JDBC driver 10.2

Activity

Show:
Julien Kronegg
August 7, 2009, 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).

KrashanK
March 4, 2010, 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

Ufuk Cemen
August 17, 2010, 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.

Strong Liu
October 13, 2011, 12:07 PM
Brett Meyer
March 7, 2014, 10:09 PM

Bulk closing tickets resolved in released versions

Assignee

Strong Liu

Reporter

Markus Heiden

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure