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

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


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

@Lob@Columnfinal 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..)


Since length is defined in the JPA spec and javadocs as int type and max is not an int then it's safe to assume that you're consigned to the columnDefinition datastore-dependent route. But then varchar(max) is datastore-dependent anyway.


Hi the below code fixed the same issue

@Column(columnDefinition="TEXT")@Lobfinal String someString;