Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA - How to set string column to varchar(max) in DDL

With JPA, DDL-generation for the attribute:

@Column final String someString; 

will be someString varchar(255) null

@Column(length = 1337) final String someString; 

will yield someString varchar(1337) null.

But how can I get it to produce someString varchar(max) null?

Is it possible using the length-attribute, or do I need to use the columnDefinition-attribute?

like image 312
Tobb Avatar asked May 07 '13 08:05

Tobb


People also ask

What is columnDefinition in @column annotation?

columnDefinition definition: The SQL fragment that is used when generating the DDL for the column. columnDefinition default: Generated SQL to create a column of the inferred type.

What is @column in JPA?

In this article, we will discuss how to change the column name in the Spring project using JPA. @Column annotation is used for Adding the column the name in the table of a particular MySQL database. Syntax: @Column(name=”DESC”, nullable=false, length=512)

What is @LOB in hibernate?

The @Lob annotation specifies that the database should store the property as Large Object. The columnDefinition in the @Column annotation defines the column type for the property. Since we're going to save byte array, we're using BLOB.

How long is varchar?

Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used. See Section 8.4.


1 Answers

Some months have passed, new knowledge acquired, so I'll answer my own question:

@Lob @Column final String someString; 

yields the most correct result. With the version of hbm2ddl I'm using, this will be transformed to the type text with SqlServerDialect. Since varchar(max) is the replacement for text in newer versions of SQL Server, hopefully, newer versions of hbm2ddl will yield varchar(max) instead of text for this type of mapping (I'm stuck at a quite dated version of Hibernate at the moment..)

like image 53
Tobb Avatar answered Oct 21 '22 01:10

Tobb