-->
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: What's wrong with the data mapping?
PostPosted: Sat Jul 07, 2007 9:35 pm 
Newbie

Joined: Thu Jul 05, 2007 4:58 pm
Posts: 4
Here's the packages I'm using
7-Jul-2007 9:22:16 PM org.hibernate.cfg.annotations.Version <clinit>
INFO: Hibernate Annotations 3.3.0.GA
7-Jul-2007 9:22:16 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.4.sp1
7-Jul-2007 9:22:16 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
7-Jul-2007 9:22:16 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
7-Jul-2007 9:22:16 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
7-Jul-2007 9:22:16 PM org.hibernate.ejb.Version <clinit>
INFO: Hibernate EntityManager 3.3.1.GA

With
7-Jul-2007 9:22:17 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: MySQL, version: 5.0.38-Ubuntu_0ubuntu1-log
7-Jul-2007 9:22:17 PM org.hibernate.cfg.SettingsFactory buildSettings
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 $ )
7-Jul-2007 9:22:17 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQL5Dialect

The table has following structure:
Code:
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


I got some problem when executing this query:
Code:
Query query = em.createNativeQuery("select PREFIX from IN_CATEGORY where PREFIX='IC'");
Object result = query.getSingleResult();
System.out.println(result + " is of " + result.getClass());


Query output:
Code:
Hibernate:
    select
        PREFIX
    from
        IN_CATEGORY
    where
        PREFIX='IC'
I is of class java.lang.Character


How... can this be right? Isn't char length > 1 suppose to be converted to String??


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 07, 2007 10:19 pm 
Newbie

Joined: Thu Jul 05, 2007 4:58 pm
Posts: 4
So I did a little digging, using native JDBC calls like this:
Code:
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection c =  java.sql.DriverManager.getConnection(URL);
Statement s = c.createStatement();

s.execute("select PREFIX from IN_CATEGORY WHERE PREFIX='IC'");
ResultSet rs = s.getResultSet();

System.out.println(rs.next () + " " + rs.getObject(1) + " " + s.getObject(1).getClass());


And the result is:
Code:
true IC class java.lang.String


Now I'm really confused... if the JDBC returned the result as String, why would I get java.lang.Character when using createNativeQuery()?


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.