Hibernate + Oracle + Clob: attribute contents switch

Has anyone heard of this error before:

I have a Java 5 application that uses Hibernate 3.3.2 to access Oracle Database 10g, the JDBC driver is the lightweight Oracle driver version 10.2.0.4.0 (the latest version, I think). Access to the database occurs during a transaction, which is managed using spring AOP tools. There is one database table mapped to a single Java object, mapping is done using annotations. There are two attributes in this object that are CLOBs in the database. They are annotated according to JPA with "Lob" and are Java strings. Everthing works fine if both attributes have no values ​​with more than 4000 characters: after fixing, the values ​​are included in the database, that is, attribute A contains the value of attribute B and vice versa.

I'm not kidding!

The Eclipse debugger tells me that the Java object has the correct values ​​before closing the transaction (I did not debug spring transaction processing). This error does not occur if both Clobs are annotated with the Hibernate annotation "Type (type =" clob ")" (in this case they should be of type java.sql.Clob, not String, of course).

+3
source share
4 answers

Meanwhile, I found a solution to the problem: the SQL dialect was incorrect, someone installed it in Oracle9 instead of the correct version, which is:

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

Setting the correct SQL dialect solves the problem :-)

0
source

100%, SetBigStringTryClob true (. CLOB JDBC?).

Spring, - :

<property name="hibernateProperties">
  <props>
    <prop key="hibernate.connection.SetBigStringTryClob">true</prop>
  </props>
</property>
0

. CLOB . , . . 4000 . bean . , org.hibernate.dialect.Oracle10gDialect . ( Hibernate 4.2.2.Final)

// updatable = false JPA, CLOB. , , .

0

, , hql- . CLOB ( ):

Query query = em.createQuery("update SomeTable as someTable set value = :value where id = :id");
query.setParameter("value", value);
query.setParameter("id", id);
if (query.executeUpdate() != 1) {
    throw new Exception("Value update had no effect");
}
0

Source: https://habr.com/ru/post/1753127/


All Articles