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?
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.
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)
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.
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.
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..)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With