-->
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: Clobs, Oracle 10G, and 2.1
PostPosted: Fri Dec 15, 2006 10:45 pm 
Newbie

Joined: Fri Mar 24, 2006 2:07 pm
Posts: 8
I have an object A, that has a collection of objects B. The B object has a clob field that is mapped to 'text' in the mapping file.

I load the A object, it loads up the collection of Bs (as it should cascade='all-delete-orphan'), but some B objects end up with extra crap appended to the end of their clob field. It looks almost like the driver (or something fairly low level) is reusing a buffer but not clearing it out or cleanly terminating the string data correctly.

So as a made up example I have two B's that look like this in the database:

B1: Some Data
B2: Test

When I look at them in the debugger in java after they have been loaded I see:

B1: Some Data
B2: Teste Data

Then to make matters worse if I then save A it writes the new version of B2 out to the database and thus corrupts the data in the database.

We are using oracle 10G with the latest JDBC driver and hibernate 2.1.8

Looking through the forums there seem to be various other issues with clobs and oracle, but I didn't see anything that seemed completely similar to this problem.

Any thoughts?


Top
 Profile  
 
 Post subject: hacky solution
PostPosted: Sat Dec 16, 2006 6:57 pm 
Newbie

Joined: Fri Mar 24, 2006 2:07 pm
Posts: 8
I 'fixed' the problem of getting extra crap returned on some of my clobs. A hack but it works.

In my mapping file I have:

<property name="extraData" type="text" column="extra_data" not-null="true">

now I added a new property:

<property name="dataLength" type="int" formula="length(extra_data)"/>


In my POJO when setExtraData(String extraData) is called,
I substring it to the dataLength.

if (getDataLength() != null) {
extraData = extraData.substring(0, getDataLength());
}

since dataLength might not be set yet, I do the same thing in setDataLength

if (getExtraData() != null) {
extraData = extraData.substring(0, getDataLength());
}

(More or less, I'm actually using a generated base class, and mapping it to a derived class which I use to make sure data is encrypted/decrypted goin g in and out of the database. So my own code is a bit more complicated, but the above is the gist of what I'm doing.)

Anyway using the 'computed' dataLength property and trimming the clob field to that value is going to be 'good enough' until I can talk people into upgrading to 3.2.

Hope this helps someone else.


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.