Grails 1.3.7 には、hibernate 3.3.1 GA がバンドルされています。このバージョンの Hibernateには存在SQLServer2008Dialect
しないと思います。2k および 2k5 バージョンに適した「SQLServerDialect」だけです。
このブログ投稿で説明されているように、このクラスを新しいバージョンから借用する必要があります
アーカイブのためにここでクラスを再現します (robert-reiz.com から)
import org.hibernate.Hibernate;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.dialect.function.*;
import org.hibernate.type.StandardBasicTypes;
import java.sql.Types;
public class SqlServer2008Dialect extends SQLServerDialect {
public SqlServer2008Dialect(){
super();
registerColumnType( Types.DATE, "date" );
registerColumnType( Types.TIME, "time" );
registerColumnType( Types.TIMESTAMP, "datetime2" );
registerFunction( "current_timestamp", new NoArgSQLFunction("current_timestamp", Hibernate.TIMESTAMP,false) );
registerColumnType( Types.BIT, "tinyint" ); //Sybase BIT type does not support null values
registerColumnType( Types.BIGINT, "bigint" );//changed
registerColumnType( Types.SMALLINT, "smallint" );
registerColumnType( Types.TINYINT, "tinyint" );
registerColumnType( Types.INTEGER, "int" );
registerColumnType( Types.CHAR, "char(1)" );
registerColumnType( Types.VARCHAR, "varchar($l)" );
registerColumnType( Types.FLOAT, "float" );
registerColumnType( Types.DOUBLE, "double precision" );
registerColumnType( Types.VARBINARY, "varbinary($l)" );
registerColumnType( Types.NUMERIC, "numeric($p,$s)" );
registerColumnType( Types.BLOB, "image" );
registerColumnType( Types.CLOB, "text" );
registerColumnType( Types.ROWID, "bigint");
registerFunction( "ascii", new StandardSQLFunction("ascii", StandardBasicTypes.INTEGER));
registerFunction( "char", new StandardSQLFunction("char", StandardBasicTypes.CHARACTER));
registerFunction( "len", new StandardSQLFunction("len", StandardBasicTypes.LONG) );
registerFunction( "lower", new StandardSQLFunction("lower") );
registerFunction( "upper", new StandardSQLFunction("upper") );
registerFunction( "str", new StandardSQLFunction("str", StandardBasicTypes.STRING) );
registerFunction( "ltrim", new StandardSQLFunction("ltrim") );
registerFunction( "rtrim", new StandardSQLFunction("rtrim") );
registerFunction( "reverse", new StandardSQLFunction("reverse") );
registerFunction( "space", new StandardSQLFunction("space", StandardBasicTypes.STRING));
registerFunction( "user", new NoArgSQLFunction("user", StandardBasicTypes.STRING) );
registerFunction( "current_timestamp", new NoArgSQLFunction("getdate", StandardBasicTypes.TIMESTAMP) );
registerFunction( "current_time", new NoArgSQLFunction("getdate", StandardBasicTypes. TIME) );
registerFunction( "current_date", new NoArgSQLFunction("getdate", StandardBasicTypes. DATE) );
registerFunction( "getdate", new NoArgSQLFunction("getdate", StandardBasicTypes. TIMESTAMP) );
registerFunction( "getutcdate", new NoArgSQLFunction("getutcdate", StandardBasicTypes. TIMESTAMP) );
registerFunction( "day", new StandardSQLFunction("day", StandardBasicTypes.INTEGER) );
registerFunction( "month", new StandardSQLFunction("month", StandardBasicTypes.INTEGER) );
registerFunction( "year", new StandardSQLFunction("year", StandardBasicTypes.INTEGER) ) ;
registerFunction( "datename", new StandardSQLFunction("datename", StandardBasicTypes. STRING) );
registerFunction( "abs", new StandardSQLFunction("abs") );
registerFunction( "sign", new StandardSQLFunction("sign", StandardBasicTypes.INTEGER) ) ;
registerFunction( "acos", new StandardSQLFunction("acos", StandardBasicTypes.DOUBLE) );
registerFunction( "asin", new StandardSQLFunction("asin", StandardBasicTypes.DOUBLE) );
registerFunction( "atan", new StandardSQLFunction("atan", StandardBasicTypes.DOUBLE) );
registerFunction( "cos", new StandardSQLFunction("cos", StandardBasicTypes.DOUBLE) );
registerFunction( "cot", new StandardSQLFunction("cot", StandardBasicTypes.DOUBLE) );
registerFunction( "exp", new StandardSQLFunction("exp", StandardBasicTypes.DOUBLE) );
registerFunction( "log", new StandardSQLFunction( "log", StandardBasicTypes.DOUBLE) );
registerFunction( "log10", new StandardSQLFunction("log10", StandardBasicTypes.DOUBLE) );
registerFunction( "sin", new StandardSQLFunction("sin", StandardBasicTypes.DOUBLE) );
registerFunction( "sqrt", new StandardSQLFunction("sqrt", StandardBasicTypes.DOUBLE) );
registerFunction( "tan", new StandardSQLFunction("tan", StandardBasicTypes.DOUBLE) );
registerFunction( "pi", new NoArgSQLFunction("pi", StandardBasicTypes.DOUBLE) );
registerFunction( "square", new StandardSQLFunction("square") );
registerFunction( "rand", new StandardSQLFunction("rand", StandardBasicTypes.FLOAT) );
registerFunction("radians", new StandardSQLFunction("radians", StandardBasicTypes. DOUBLE) );
registerFunction("degrees", new StandardSQLFunction("degrees", StandardBasicTypes. DOUBLE) );
registerFunction( "round", new StandardSQLFunction("round") );
registerFunction( "ceiling", new StandardSQLFunction("ceiling") );
registerFunction( "floor", new StandardSQLFunction("floor") );
registerFunction( "isnull", new StandardSQLFunction("isnull") );
registerFunction( "concat", new VarArgsSQLFunction( StandardBasicTypes.STRING, "( ","+",")" ) );
registerFunction( "length", new StandardSQLFunction( "len", StandardBasicTypes.INTEGER ) );
registerFunction( "trim", new SQLFunctionTemplate( StandardBasicTypes.STRING, "ltrim( rtrim(?1))") );
registerFunction( "locate", new CharIndexFunction() );
getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH);
}
}
追加する必要があります
dialect = org.hibernate.dialect.SqlServer2008Dialect
̀Datasource.groovy` 構成ファイルで、このクラスをクラスパスで使用できるようにします
警告: ブログ投稿では、Hibernate の基本バージョンは 3.6.4 であり、上記のコードSQLServer2005Dialect
は 3.3.1 GA バージョンには存在しないクラスを使用しています。SQLServerDialect
これらのクラスが互換性があると仮定しながら、これを考慮して上記のコードを変更しました (私は を使用しました)。私はこれをチェックしませんでした。