PAVAN NAIK
PAVAN NAIK

Reputation: 11

Why Hibernate and mssql jdbc driver generating VARCHAR(8000) for a column annotated with @Column( length=4000, columnDefinition = "VARCHAR(4000)")?

I am using hibernate 5.6.15 Final, SQLSERVER2016DIALECT, and mssql-jdbc-9.4.0.jre8.

I have declared following field defintion in my entity class:

@Type(type = "org.hibernate.type.StringType")
@Column(name = "DATA_STRING", length = 4000, nullable = true, updatable = true, columnDefinition = "VARCHAR(4000)")
private String DataString;

Despite specifying columnDefinition = "VARCHAR(4000)", Hibernate is generating the column as VARCHAR(8000) in its queries. This is causing issues with implicit conversions in my SQL Server database. The table is defined in SQL Server as:

CREATE TABLE CUST_DATA (
DATA_STRING VARCHAR(4000) NULL,
);

Questions:

1.Why is MSSQL JDBC DRIVER 9.4.0.jre8 overriding the specified length of 4000 and generating VARCHAR(8000)?

2.Is there a way to enforce the correct length in the generated query?

Upvotes: 1

Views: 72

Answers (0)

Related Questions