[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2934) ScrollableResults.get(int column) returns only the first character of a database column type char(10)
Mike Farewell (JIRA)
noreply at atlassian.com
Fri Nov 9 15:14:29 EST 2007
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2934?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_28753 ]
Mike Farewell commented on HHH-2934:
------------------------------------
I think I have found a similar case:
org.hibernate.Query q = hibernateSession.createSQLQuery(
"select distinct c.alpha_2, c.alpha_3, cl.country_name, c.country from countries c " +
"inner join country_locale cl on c.alpha_2 = cl.country_alpha2 where " +
"cl.language_code = ? order by cl.country_name");
q.setString(0, locale);
results = q.list();
returns an array of objects the first two items of which are char objects with only one char in them
i.e. should return
"AD";"AND";"Andorra";"Andorra"
"AE";"ARE";"United Arab Emirates";"United Arab Emirates"
"AF";"AFG";"Afghanistan";"Afghanistan"
...
actually get
"A";"A";"Andorra";"Andorra"
"A";"A";"United Arab Emirates";"United Arab Emirates"
"A";"A";"Afghanistan";"Afghanistan"
...
The database I am using is postgresql 8.2 my postgresql database table has the following definition:
CREATE TABLE countries
(
country character varying(50) NOT NULL,
numeric_code smallint NOT NULL,
alpha_3 character(3) NOT NULL,
alpha_2 character(2) NOT NULL,
CONSTRAINT pk_countries PRIMARY KEY (alpha_2),
CONSTRAINT un_alpha_2 UNIQUE (alpha_2)
)
The work around is to cast the char fields to varchars in the select:
e.g. CAST(c.alpha_2 as varchar)
> ScrollableResults.get(int column) returns only the first character of a database column type char(10)
> -----------------------------------------------------------------------------------------------------
>
> Key: HHH-2934
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2934
> Project: Hibernate3
> Issue Type: Bug
> Components: query-sql
> Affects Versions: 3.2.4.sp1
> Environment: IBM DB2 8.1.7,
> Reporter: Samir Jyoti
>
> ScrollableResults.get(int column) returns only the first character of a database column type char(n) where n> 1 (say 10 or 18).
> So if your column has value 'SIMPSON ' , it only returns 'S'.
> Had to warp the column with a DB2 SQL "VARCHAR" function to convert it into a String.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list