0

Using DataType.LONG_STRING attribute value Persisted as SQL type LONGVARCHAR which handles longer strings.

However, i want to map the field to SQL type TEXT .

@DatabaseField(dataType = DataType.LONG_STRING)
String comment;

Since there is a difference between LONGVARCHAR and TEXT SQL Type, DataType.LONG_STRING value does not solve the problem

Community
  • 1
  • 1
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254

1 Answers1

2

So by default the LONG_STRING type is supposed to generate TEXT as the schema -- Postgres and MySQL do for example. What database type are you using? Derby generates LONG VARCHAR, Hsqldb LONGVARCHAR, and Oracle LONG. I think this was for compatibility reasons.

There a couple of ways that you can override the schema that ORMLite produces. The easiest is to define the column yourself with the columnDefinition part of the @DatabaseField:

@DatabaseField(columnDefinition = "TEXT")
String comment;

If you are making more complex changes to the database compability code, you can also override the DatabaseType you are using. In this case you can override the appendLongStringType(...) method to produce a different schema. I'd override DerbyDatabaseType or whatever database you are using and then add something like:

@Override
protected void appendLongStringType(StringBuilder sb, FieldType fieldType,
    int fieldWidth) {
    sb.append("TEXT");
}
Gray
  • 115,027
  • 24
  • 293
  • 354
  • Well I'm not a mind reader so I didn't know. MySQL should generated `TEXT` for `DataType.LONG_STRING`. I've just tested it and it does. What version of ORMLite are you using? Is it possibly using the wrong database type @AbdennourToumi? – Gray May 13 '13 at 15:20
  • i use the last =>4.45 .thanks again for this tracking.But,if DataType.LONG_STRING generates TEXT what about LONGVARCHAR – Abdennour TOUMI May 13 '13 at 16:20
  • 1
    Well, you change the `columnDefinition` field above. Right @AbdennourToumi? – Gray May 13 '13 at 16:26