views:

37

answers:

2

Has anyone heard of this error before:

I have a Java 5 application, that uses Hibernate 3.3.2 to access an Oracle Database 10g, the JDBC driver is the Oracle light driver version 10.2.0.4.0 (the most recent version, I think). The database access happens during a transaction that is managed via the AOP-tools of spring. There is one database table mapped to one Java entity, the mapping is done via annotations. There are two attributes in this entity that are CLOB in the database. They are annotated according to JPA with "Lob" and are Java Strings. Everthing works fine unless both attributes have values with more than 4000 characters: After the commit the values are switched on the database, that is attribute A contains the value of attribute B and vice versa.

This is not a joke!

The Eclipse debugger tells me that the Java entity has the correct values until the transaktion closes (I did not debug into the spring transaction handling). This error does not occur if both Clobs are annotated with the Hibernate annotation 'Type(type = "clob")' (in which case they have to be of the type java.sql.Clob and not String, of course).

A: 

I'm not 100% sure but could you try to set the connection property SetBigStringTryClob to true (see How To Handle CLOBs Easily in JDBC?).

If you are using Spring, something like this:

<property name="hibernateProperties">
  <props>
    <prop key="hibernate.connection.SetBigStringTryClob">true</prop>
  </props>
</property>
Pascal Thivent
Yes, thanks, that's supposed to fix errors with more than 32kB in a CLOB-Attribute, I did try that to no avail. There are several questions here on stackoverflow and elsewhere about problems with one single CLOB attribute and content over 4000 characters or more. I hope I found them all :-) Note that my problem occurs only when at least two attributes have more than 4000 characters.
Tim van Beek
@Tim TBH, this was more a shot in the dark. Actually, your case is really strange (and I wonder *who* is swapping the values) and smells like a nasty bug somewhere. Adding this question to my favorite to follow this story.
Pascal Thivent
My guess is that a) CLOB values need a special handling when containing more than 4000 characters, and b) either Hibernate or the Oracle JDBC driver has an error that switches the values if there is more than one that needs this extra handling. But I cannot afford the time to debug both, and I did not find a similar bug in the Hibernate bug DB. (I can't simply upgrade Hibernate, because the software is used in production and changing the whole Hibernate distribution would necessitate a thorough test of the whole software).
Tim van Beek
@Tim a) Yes, which is why I suggested to try the above option b) I would run a simple JDBC test to see how the JDBC driver behave with raw JDBC code. If you reproduce the problem, then you'll know where it is :)
Pascal Thivent
A: 

Meanwhile I found a solution to the problem: The SQL-dialect was wrong, someone set it to Oracle9 instead of the correct version, which is this:

name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"

Setting the correct SQL-dialect solves the problem :-)

Tim van Beek