Abdennour TOUMI
Abdennour TOUMI

Reputation: 93333

Persist Text SQL Type via ORMLite (not LONGVARCHAR)

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

Upvotes: 0

Views: 704

Answers (1)

Gray
Gray

Reputation: 116908

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");
}

Upvotes: 2

Related Questions