Java Mailing List Archive

http://www.gg3721.com/

Home » Hibernate Issues List »

[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2220)
session.createSQLQuery(sql)
translates database type CHAR(n) to Java type char instead of String

Anupam M (JIRA)

2008-08-12

Replies: Find Java Web Hosting

Author LoginPost Reply

  [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2220?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_30832 ]

Anthony Patricio commented on HHH-2220:
---------------------------------------

you can set the expected behavior by extending the dialect you're using and registering the hibernate type :
registerHibernateType(Types.CHAR, 2, Hibernate.STRING.getName());
or
registerHibernateType(Types.CHAR, 2, Hibernate.CHARACTER_ARRAY.getName());

> 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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

   
_______________________________________________
hibernate-issues mailing list
hibernate-issues@(protected)
https://lists.jboss.org/mailman/listinfo/hibernate-issues
©2008 gg3721.com - Jax Systems, LLC, U.S.A.