Hibernate should not use LONG type for Oracle

Description

This is a spin-off from http://stackoverflow.com/questions/3719905/why-has-hibernate-switched-to-use-long-over-clob/3721717.

With the changes introduced in https://hibernate.atlassian.net/browse/HHH-3892#icft=HHH-3892 Hibernate started to use Oracle LONG type instead of CLOB for properties of type="text". This is a bad idea because of the following:

  • it creates huge amount of pain for people who depend on Hibernate automatically creating table structure for them. Tables created with the same mapping will have different structure than tables created with earlier version of Hibernate

  • Oracle LONG type has a limitation: there can be only one column of this type within a single table;

  • Oracle has deprecated LONG type many years ago and advised against using this type ever since 8i. See http://www.orafaq.com/wiki/LONG.

Defining a property to have type="clob" is not really a solution; other databases might have other, more suitable types to store this type of data (not necessarily CLOB).

At the moment the only workaround is to define custom dialact and use it; but this is a very poor solution in the long term.

Activity

Show:

Lukas Eder July 5, 2019 at 2:47 PM

I'm not sure what the motivation was to switch to LONG at that time, but already then, the type has been deprecated by Oracle for 12 years as has been mentioned before. It is not recommended to continue using this type in new tables:
https://docs.oracle.com/en/database/oracle/oracle-database/18/sqlrf/Data-Types.html#GUID-4C0B65DB-E751-4957-A1ED-5044BAFA7812

LONG Data Type
Do not create tables with LONG columns. Use LOB columns (CLOB, NCLOB, BLOB) instead. LONG columns are supported only for backward compatibility.

I strongly recommend reopening this issue and reconsidering this mapping for Oracle. Of course, the workaround is to add a @Lob annotation, but this is very easily forgotten, especially when an application supports several dialects - as few of the other dialects need the @Lob annotation.

Steve Ebersole March 21, 2011 at 7:08 PM

Bulk closing stale resolved issues

Albert Guðmundsson February 2, 2011 at 6:48 PM

Hibernate should map "text" to CLOB for Oracle as LONG is a deprecated datatype that should not be used.

Former user January 22, 2011 at 6:06 AM

> Firstly, you did not address the problem raised by this bug: Hibernate is using deprecated database type. Can you provide any rational argument why would Hibernate want to do that?

MySQL and Sybase have a "text" data type, but both map to JDBC LONGVARCHAR. The problem is that Hibernate's "text" type could not be used with MySQL((HHH-3161) or Sybase (HHH-3691)) because it was mapped to CLOB. Hibernate's "text" type was specifically changed to map to LONGVARCHAR to support MySQL and Sybase and other databases that have a "text" data type.

Oracle maps "long" to JDBC LONGVARCHAR, and that is why Hibernate now maps "text" as "long" for Oracle. At the time I worked on this stuff, I did not see any other alternative. Did I miss something?

> Secondly, you broke backwards compatibility (when one Hibernate type suddenly starts to be mapped onto another on a specific Hibernate version). There is nothing in any release notes of Hibernate that mention people need to update from using one type to another.

Yes, you got me on that one, and I'm very sorry about that oversight. I've added this information to a "Hibernate Core Migration Guide : 3.5" at (http://community.jboss.org/docs/DOC-16370). Please let me know if what I wrote is unclear.

> Finally, how would that affect other databases? For example, Hibernate text type is very convenient to use on other databases, such as MySQL.

See above.

MindaugasM January 11, 2011 at 1:04 PM

This resolution is very disappointing.

Firstly, you did not address the problem raised by this bug: Hibernate is using deprecated database type. Can you provide any rational argument why would Hibernate want to do that?

Secondly, you broke backwards compatibility (when one Hibernate type suddenly starts to be mapped onto another on a specific Hibernate version). There is nothing in any release notes of Hibernate that mention people need to update from using one type to another.

Finally, how would that affect other databases? For example, Hibernate text type is very convenient to use on other databases, such as MySQL.

Rejected

Details

Assignee

Reporter

Components

Affects versions

Priority

Created September 16, 2010 at 11:32 AM
Updated July 5, 2019 at 2:47 PM
Resolved January 11, 2011 at 12:22 AM