3
votes

There is an error in the log that says:

ORA-01461: can bind a LONG value only for insert into a LONG column

no other useful info really. I tried to follow up on the code, google-d the problem and I think I might have found the problem, but unfortunately I do not have Oracle database or anything really (even the code isn't present to me, I'm writing all this from memory and notes :( ) So the only thing I can guess based on the code (and lots of googling) is the String mapping to varchar2. Some environment info:

Hibernate: 3.2.1.ga
Driver: ojdbc6-11.2.0.2.0.jar
Database: 11.2.0.2.0 - 64bit

The table has multiple varchar2(300 byte) and one varchar2(4000 byte), lets call this last one TEXT. I checked the entity, and in it's column annotation these fields have a restriction of 300 bytes to its value, even the TEXT (4000 byte) field! So that's one strange point. My wild guess is that a String comes, bigger then 300 BYTE, and this is the error that gets printed into the log when trying to persist (stack trace points where the code tries to persist an instance of this entity). Sadly I only have that log to go on.. :( Is my guess likely? Or it's going to be something else?

Here's the entity field:

@Column(name = "TEXT", nullable = false, length = varcharLength)
public String getText() {
    return text;
}

Here is the create statement (the essential part anyway):

CREATE TABLE "TABLENAME" 
   (
   "ID" VARCHAR2(300 BYTE) NOT NULL ENABLE, 
   "VERSION" NUMBER(10,0), 
   "TEXT" VARCHAR2(4000 BYTE) NOT NULL ENABLE, 
   "PUBLISH_DATE" DATE NOT NULL ENABLE, 
   PRIMARY KEY ("ID")
   );

(And the table has an index on PUBLISH_DATE, if that is relevant at all.)

1
Sounds like a Hibernate bug/problem then. Are you using the correct hibernate dialect?a_horse_with_no_name
<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" />Revolit
I think you should use org.hibernate.dialect.Oracle10gDialect as OracleDialect is deprecated: docs.jboss.org/hibernate/core/3.2/api/org/hibernate/dialect/…a_horse_with_no_name
Thank you, I will try that as soon as possible.Revolit
Changing the dialect did not solve the problem, but I get the error if I try to insert a String bigger then the restriction in the schema. We'll have to use clob I guess or write the check in Java.Revolit

1 Answers

5
votes

So, it was a problem with bigger String then 4000 byte. We changed the column to CLOB, this should solve it. And if the character literal is smaller then 4000 byte, it still gets stored in Oracle as if it would be varchar2(4000).