-->
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.  [ 6 posts ] 
Author Message
 Post subject: use char(2) as primary key in oracle,and can not get record
PostPosted: Wed Apr 27, 2005 4:40 am 
Newbie

Joined: Fri Apr 22, 2005 4:09 am
Posts: 6
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.0

Name and version of the database you are using:oracle

Hi all,
I use char(2) as primary key in my table in oracle,but I can not get the existing record using session.get(String entityName, Serializable id).

following is mapping file,I use dynamic-class

<class entity-name="A_TEST">
<id name="id" type="string">
<column name="id" sql-type="char(2)"/>
<generator class="assigned"/>
</id>
<property name="name" column="name" type="string"/>
</class>

following is my code:
...
session.get("A_TEST","1");
...
there is a record whose primary key is "1" certainly,why?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 27, 2005 8:10 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
char fields in oracle are always same length and there isn't field '1', than '1 '
oracle add padding blank for char field automatic
Don't use it - use varchar2

regards


Top
 Profile  
 
 Post subject: But I can not alter the table structure
PostPosted: Wed Apr 27, 2005 9:32 pm 
Newbie

Joined: Fri Apr 22, 2005 4:09 am
Posts: 6
thx! But I can not alter the table structure..


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 7:15 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
then add padding blank before query or load


Top
 Profile  
 
 Post subject: can u explain in detail?thx
PostPosted: Fri Apr 29, 2005 9:48 pm 
Newbie

Joined: Fri Apr 22, 2005 4:09 am
Posts: 6
thx for your response!snpesnpe

But I can't catch your meaing of "then add padding blank before query or load",please explain in detail.thx!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 29, 2005 11:19 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
call
session.get("A_TEST","1 "); // add blank after 1;
except
session.get("A_TEST","1");

Oracle add blank in char field - you can see this from sqlplus with ;

select id,length(id)
from a_test

length(id) is always 2 if column defined char(2)

regards


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