[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2220?page=c...
]
Allen Yu commented on HHH-2220:
-------------------------------
The problem is also confirmed on MYSQL
INFO: RDBMS: MySQL, version: 5.0.38-Ubuntu_0ubuntu1-log
INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.0.6 ( $Date:
2007-03-09 22:13:57 +0100 (Fri, 09 Mar 2007) $, $Revision: 6341 $ )
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
Other settings:
INFO: Hibernate Annotations 3.3.0.GA
INFO: Hibernate 3.2.4.sp1
INFO: using JDK 1.4 java.sql.Timestamp handling
INFO: Hibernate EntityManager 3.3.1.GA
Temporary solution:
Problem can be solved by forcing Hibernate.STRING type on the column.
CREATE TABLE `IN_CATEGORY` (
`CATEGORY_ID` int(11) NOT NULL auto_increment,
`PREFIX` char(2) NOT NULL,
`EXTENSION` char(3) NOT NULL,
`PARENT_ID` int(11) default NULL,
PRIMARY KEY (`CATEGORY_ID`),
UNIQUE KEY `CATEGORY` (`PREFIX`,`EXTENSION`),
KEY `FK_PARENT_ID` (`PARENT_ID`),
CONSTRAINT `FK_PARENT_ID` FOREIGN KEY (`PARENT_ID`) REFERENCES `IN_CATEGORY`
(`CATEGORY_ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Ex.
SQLQuery query = session.createSQLQuery("SELECT PREFIX, EXTENSION FROM
IN_CATEGORY");
query.addScalar("PREFIX", Hibernate.STRING);
query.addScalar("EXTENSION", Hibernate.STRING);
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