[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2220?page=c...
]
Hank Kuivila commented on HHH-2220:
-----------------------------------
I've had the same issue. Here's a test scenario:
The java code used is:
//PersistenceUtil is just a global that acquires/release/holds sessions
Session s = PersistenceUtil.currentSession();
s.createSQLQuery("create table #t (a char(10), b
varchar(10))").executeUpdate();
s.createSQLQuery("insert #t values ('foo',
'bar')").executeUpdate();
s.createSQLQuery("insert #t values ('mint',
'twinky')").executeUpdate();
for (Object o : s.createSQLQuery("select * from #t").list()){
Object[] oa = (Object[]) o;
System.out.println(oa[0] + ", " + oa[1]);
}
I'm using Hibernate 3.2.2, here's all the relevant log data with show sql:
- Hibernate 3.2.2
- hibernate.properties not found
- Bytecode provider name : cglib
- using JDK 1.4 java.sql.Timestamp handling
- configuring from resource: /hibernate.cfg.xml
- Configuration resource: /hibernate.cfg.xml
...........
- RDBMS: Microsoft SQL Server, version: Microsoft SQL Server 2000 - 8.00.2039 (Intel X86)
May 3 2005 23:18:38
Copyright (c) 1988-2003 Microsoft Corporation
Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 1)
>>>>>>>>> we create a table:
Hibernate: create table #t (a char(10), b varchar(10))
................
>>>>>>>>>>> we put some values into
the table:
Hibernate: insert #t values ('foo', 'bar')
Hibernate: insert #t values ('mint', 'twinky')
>>>>>>>>>>> we retrieve values and
print them
Hibernate: select * from #t
>>>>>>>>>>> and lose the oo of foo
and the int of mint
f, bar
m, twinky
session.createSQLQuery(sql) translates database type CHAR(n) to Java
type char instead of String
------------------------------------------------------------------------------------------------
Key: HHH-2220
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2220
Project: Hibernate3
Issue Type: Bug
Components: query-sql
Affects Versions: 3.2.0.ga
Reporter: Regis Pires Magalhaes
createSQLQuery() method translates database type CHAR(n) to Java type char instead of
String when using setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP).
That happens when I do not use addScalar(). And that is the only problem that I have
found when not filling return types in advance.
A workaround I have made is to concatenate the projected field with an empty string
(''). See example below:
...
query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
String sqlQuery = "select s.name state from state s where s.name='PI'
";
query = session.createSQLQuery(sqlQuery);
...
result: [{STATE=P}]
name field is CHAR(2) in database definition (PostgreSQL, HSQLDB and Oracle were
tested).
Note that it works when I concatenate the field used in projection with an empty string:
...
String sqlQuery = "select s.name || '' state from state s where
s.name='PI' ";
...
result: [{STATE=PI}]
--
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira