-->
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.  [ 5 posts ] 
Author Message
 Post subject: Returns only the first character of a db column type char(8)
PostPosted: Wed Nov 19, 2008 4:17 pm 
Newbie

Joined: Wed Nov 19, 2008 2:25 pm
Posts: 3
Database using: SQLserver 2005
Hibernate Version: 3.2.5

Problem Description:

We have a USER table with following columns
1) UserId char(8)
2) UserFName varchar(30)
3)USerLName varchar(30)

List result = hibernateSession.createSQLQuery(" from USER where UserId = 'abcd' ").list();

Above query is working fine and I getting the result.

List result = hibernateSession.createSQLQuery("select UserId from USER ").list();

this is returning only the first character of all the UserIds from the table.

Any fix for this issue?

Thanks,
Jithesh


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 7:49 pm 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
Can you show us the annotations used for the mapping of that class and field?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 8:11 pm 
Newbie

Joined: Wed Nov 19, 2008 2:25 pm
Posts: 3
This is the mapping I am using in .hbm file

<property name="userId" type="string" column="UserId" />


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 11:47 pm 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
Maybe this is an issue with hibernate mapping somehow the char[8] to a byte[8] and then messing up the translation to unicode?

You can either test by changing the db to varchar(8) or trying to map to a char[] (change the java type).

Let us know what you find :-)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2008 12:09 pm 
Newbie

Joined: Wed Nov 19, 2008 2:25 pm
Posts: 3
Hi,

Thanks for your reply.

I know it will work perfectly if I change char data type to varchar datatype.

But i cannot do that, we are using char data type in lot of tables.

I tested char[] too but no luck.

If I execute the query like a normal sql it will work perfectly.

I am using the following code.

Connection connection = session.connection();
PreparedStatement preparedStatement = connection.prepareStatement("Select UserId from USER");
ResultSet resultSet = preparedStatement.executeQuery();

Thanks,
Jithesh


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.