Pregunta

I am using hibernate.hbm2ddl.auto to create my tables.

Creating my column like this:

@Column(name = "foo", length = 8000)
private String foo;

This creates a table and the field : varchar(8000)

What I need, is that I can make save a longer string than 8000 in there. Like 20000 or more.

When changing the length higher than 8000, it won't create the table.

When changing the field manually, then it says:

The size (20000) given to the column 'foo' exceeds the maximum allowed for 
any data type (8000).
¿Fue útil?

Solución

As recommended to use Clob for such large string column

@Lob indicates that the property should be persisted in a Blob or a Clob depending on the property type: java.sql.Clob, Character[], char[] and java.lang.String will be persisted in a Clob. java.sql.Blob, Byte[], byte[] and serializable type will be persisted in a Blob.

@Lob
public String getFullText() {
    return fullText;
}

@Lob 
public byte[] getFullCode() {
    return fullCode;
}

If the property type implements java.io.Serializable and is not a basic type, and if the property is not annotated with @Lob, then the Hibernate serializable type is used.

Check example here

http://tonyyan.wordpress.com/2008/10/28/clob-and-blob-saved-through-hibernate/

Otros consejos

You could try using columnDefinition="LONGVARCHAR" instead of length = 8000. If using with org.hibernate.dialect.SQLServer2005Dialect it should be translated to varchar(max), that is able to support strings up to 2G in lengths.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top