-->
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.  [ 10 posts ] 
Author Message
 Post subject: Diference between type="text" and sql-type="t
PostPosted: Fri Nov 21, 2003 5:56 am 
Newbie

Joined: Thu Nov 06, 2003 8:28 am
Posts: 8
I want to store a String property (name) in an sql TEXT column.
I first tried this:
Code:
<property name="name" type="text">

The column was indeed a TEXT column, but when 'name' was fetched from the database it always had length 2048 (it had '\0' characters appended to it).
Then it tried it with sql-type:
Code:
<property name="name">
    <column name="NAME" sql-type="text"/>
</property>

which did what I expected.
So what is the exact meaning and purpose of type="text"?

BTW, I'm using MySql.

Ivo


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 8:02 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
It does the same on MS SQL Server and Oracle 9i.

According to what I can see, Hibernate treats the TEXT types as CLOBS. Unfortunately, JDBC drivers seems to always return a fixed amount of bytes, padded with \0. But the TextType implementation doesn't check for this end-of-string marker...

Just wondering if it is on purpose or if Gavin thought the drivers would behave differently ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 8:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ummmmm ... its certainly not intended ...

Which drivers did you try?


Have a look at what needs to be changed in TextType and submit a patch to JIRA.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 8:15 am 
Newbie

Joined: Thu Nov 06, 2003 8:28 am
Posts: 8
I used MySQL Connector/J 3.0.7 Stable (MM.MySQL)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 8:48 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
gavin wrote:
Ummmmm ... its certainly not intended ...

Which drivers did you try?


Mysql: MySQL 3.0.9 stable
MSQLServer: JConnect 3.30
Oracle: ojdbc14.jar

Quote:
Have a look at what needs to be changed in TextType and submit a patch to JIRA.


Changes are quite straightforward - you were just adding your byte buffer into the string without taking into account the amount of data you read ;-)

I have corrected this code and it works pretty well. I'll submit the thing to Jira as you propose.

When reading the TextType code, I notice that you were using deprecated java.io classes (deprecated since JDK 1.1) - ie. StringBufferInputStream and others.
In fact, we should now be using java.io.Reader's to properly convert from bytes to char...
Doing so will result in Hibernate not working on JDK 1.0 - is it a problem ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 9:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Nah, Hibernate already needs patching to run on pre-1.2 vms.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 9:16 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Ok, perfect then.

Another question - below is part of the code for the set method:
Code:
st.setAsciiStream( index, new StringBufferInputStream(str), str.length() );


Problem is the StringBufferInputStream is deprecated as well.

Just wondering why you had to go via a Stream instead of setting the string directly as follows:
Code:
st.setString( index, str);


Are there any reason to do so ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 9:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Some JDBC drivers (Oracle, in particular) behave better when passed streams than when passed very long strings or byte arrays. Sounds crazy, I know.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 10:36 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Patch submitted to JIRA (HB-486)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 11:06 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Just wondering if using the mapping:

Code:
<property name="name" type="text" />

is a better approach to use CLOB than the one described at http://www.hibernate.org/76.html (Mapping a Clob to a String)

?


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