These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: problem with native sql query (unmapped) links Char(5) with
PostPosted: Tue Nov 07, 2006 1:04 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1
Name and version of the database you are using:
Oracle 10g

When I run this native SQL query in oracle through Hibernate "select 'hello' from dual".

It returns the Character "h" in Java. The reason is that in the dialect, it maps the type "Char" in the DB to Character in Java. This doesnt seem like th ebest choice since Char in Oracle can be more than size 1... In this case size 5. The same behavior occurs with native unmapped sql to a char column in the DB. If I do this, it fixes it:

Code:
      Dialect dialect = ((SessionFactoryImpl)this.session.getSessionFactory()).getDialect();

      if (dialect instanceof Oracle9Dialect) {
        //there is a native sql problem where "char" database types get truncated since
        //read as char, so we will read them as String
        FastReflectionUtils.callMethod(Dialect.class, dialect, "registerHibernateType",
            new Class[]{int.class, String.class}, new Object[]{Types.CHAR, Hibernate.STRING.getName()}, false, true);
      }


Maybe this change should go into the Hibernate codebase in the Oracle9i dialect where it registers JDBC types with hibernate types???

Thanks,
Chris


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 2:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
what we actually need is a conversion from (jdbc-type, length, scale, precision) to an Hibernate Type.

The mechanics are already there the other way around, just need to add the "inverse".

In any case using reflection to fix it is wrong even as a workaround.

You should simply just extend the dialect and re-register the types you want handled differently.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.