15

It looks like that Hibernate started using LONG data type in version 3.5.5 (we upgraded from 3.2.7) instead of CLOB for the property of type="text".

This is causing problems as LONG data type in Oracle is an old outdated data type (see http://www.orafaq.com/wiki/LONG) that shouldn’t be used, and tables can’t have more than one column having LONG as a data type.

Does anyone know why this has been changed?

I have tried to set the Oracle SetBigStringTryClob property to true (as suggested in Hibernate > CLOB > Oracle :(), but that does not affect the data type mapping but only data transfer internals which are irrelevant to my case.

One possible fix for this is to override the org.hibernate.dialect.Oracle9iDialect:

public class Oracle9iDialectFix extends Oracle9iDialect {
  public Oracle9iDialectFix() {
    super();
    registerColumnType(Types.LONGVARCHAR, "clob");
    registerColumnType(Types.LONGNVARCHAR, "clob");
  }
}

However this is the last resort - overriding this class is step closer to forking Hibernate which I would rather avoid doing.

Can anybody explain why this was done? Should this be raised as a bug?

[UPDATE]: I have created https://hibernate.atlassian.net/browse/HHH-5569, let's see what happens.

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
mindas
  • 26,463
  • 15
  • 97
  • 154
  • Have you tried using a later version of the dialect? We found switching to the 10g dialect helped a ton with some of that. edit: I assume you are using this to generate a ddl - is that correct? – aperkins Sep 15 '10 at 17:50
  • We are using Hibernate's feature which automatically creates tables on demand if they were not present. That said, this change makes our life extremely painful as tables on newer installations will have different structure than tables in older installations. Thanks for your advice though, I'll have a look at 10g dialect tomorrow. – mindas Sep 15 '10 at 18:03
  • 1
    12 years later...your post save my day! `registerColumnType(Types.LONGVARCHAR, "clob");` was what's help me – Camille Oct 04 '22 at 15:14

3 Answers3

4

Can anybody explain why this was done? Should this be raised as a bug?

This has been done for HHH-3892 - Improve support for mapping SQL LONGVARCHAR and CLOB to Java String, SQL LONGVARBINARY and BLOB to Java byte[] (update of the documentation is tracked by HHH-4878).

And according to the same issue, the old behavior was wrong.

(NOTE: currently, org.hibernate.type.TextType incorrectly maps "text" to java.sql.Types.CLOB; this will be fixed by this issue and updated in database dialects)

You can always raise an issue but in short, my understanding is that you should use type="clob" if you want to get the property mapped to a CLOB.

PS: Providing your own Dialect and declaring it in your Hibernate configuration (which has nothing to do with a fork) is IMHO not a solution on the long term.

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • 1
    To change all the mappings to use type="clob" is a bad idea. First, this would affect tables in all other databases we support - and would require huge amounts of testing. Secondly, field in the other databases might be mapped to another type (not necessarily clob) which is more appropriate for them. And finally, this doesn't solve the problem - what's the point of starting to use a type which is inferior? – mindas Sep 16 '10 at 09:17
  • 1
    @mindas Ask the question to the Hibernate developers. But extending the dialect seems to be your best option then (and this really has nothing to do with a fork). – Pascal Thivent Sep 16 '10 at 09:27
  • Thanks Pascal, I have raised an issue (also updated this post). – mindas Sep 16 '10 at 09:38
  • @Mindas Thanks for posting the issue. Going to follow this one. – Pascal Thivent Sep 16 '10 at 09:44
4

It looks like the resolution to this issue is to use materialized_clob, at least that's what's being said by Gail Badner on HHH-5569.

This doesn't help me at all (and I left relevant comment about that) but might be helpful for someone else here. Anyway the bug is rejected and there is very little I can do about it but use overriden dialect :(

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
mindas
  • 26,463
  • 15
  • 97
  • 154
  • Thank you! This hint helped me in solving my postgreSQL mapping issue. I can now remap materialized_clobs to the type I want (TextType in my case). – Wytze Jun 25 '13 at 12:34
1

I cannot answer your question about why, but for Hibernate 6, it seems they're considering switching back to using CLOB

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509