Skip to content

Instantly share code, notes, and snippets.

@vgrichina
Created November 3, 2009 22:51
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vgrichina/225543 to your computer and use it in GitHub Desktop.
Save vgrichina/225543 to your computer and use it in GitHub Desktop.
Improved MSSQL dialect for Hibernate (using more appropriate data types)
/*
* Copyright © 2009, Componentix. All rights reserved.
*/
package com.componentix.hibernate.dialect;
import java.sql.Types;
/**
* A proper dialect for Microsoft SQL Server 2000 and 2005.
*
* @author Yuri Sakhno (George1)
*/
public class SQLServerDialect extends org.hibernate.dialect.SQLServerDialect {
/**
* Initializes a new instance of the {@link SQLServerDialect} class.
*/
public SQLServerDialect() {
registerColumnType(Types.BIGINT, "bigint");
registerColumnType(Types.BIT, "bit");
registerColumnType(Types.CHAR, "nchar(1)");
registerColumnType(Types.VARCHAR, 4000, "nvarchar($l)");
registerColumnType(Types.VARCHAR, "nvarchar(max)");
registerColumnType(Types.VARBINARY, 4000, "varbinary($1)");
registerColumnType(Types.VARBINARY, "varbinary(max)");
registerColumnType(Types.BLOB, "varbinary(max)");
registerColumnType(Types.CLOB, "nvarchar(max)");
}
}
@datla
Copy link

datla commented Jun 29, 2015

Hello there,

We're currently running into the following problem while our Dialect class extends SQLServer2012Dialect any suggestions will be greatly appreciated.

14:44:29,884 ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper Only dates between January 1, 1753 and December 31, 9999 are accepted.

Just to give you a background :

My dialect class datetime looks like this :

registerColumnType(Types.DATE, "datetime2(0)");

and I've updated all my SQL date fields to datetime2(0) do you see any issue why I've ended up in the error above ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment