-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: [RESOLVED] Support SQL Server 2012 in Hibernate 3.5.6-Final
PostPosted: Fri Jul 17, 2015 4:24 am 
Newbie

Joined: Sun Mar 15, 2009 5:31 am
Posts: 6
I succeeded in SQL Server 2012 support. So here is the steps. I hope it helps someone.

1. Define hibernate.dialect=com.xpto.hibernate.extras.dialect.SQLServer2012Dialect

2. Code:
Code:
package com.xpto.hibernate.hibernate.extras.dialect;

import java.sql.Types;

import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.dialect.function.NoArgSQLFunction;
import org.hibernate.type.IntegerType;
import org.hibernate.type.TimestampType;

/**
* Microsoft SQL Server 2012 Dialect
*
* @author marcos.sousa
*/
public class SQLServer2012Dialect extends SQLServerDialect {

   private static final int MAX_LENGTH = 8000;

   /**
    * Initializes a new instance of the {@link SQLServerDialect} class.
    */
   public SQLServer2012Dialect() {
      // SQL Server 2005 Dialect
      // HHH-3965 fix
      // As per http://www.sql-server-helper.com/faq/sql-server-2005-varchar-max-p01.aspx
      // use varchar(max) and varbinary(max) instead of TEXT and IMAGE types
      registerColumnType(Types.BLOB, "varbinary(MAX)");
      registerColumnType(Types.VARBINARY, "varbinary(MAX)");
      registerColumnType(Types.VARBINARY, MAX_LENGTH, "varbinary($l)");
      registerColumnType(Types.LONGVARBINARY, "varbinary(MAX)");

      registerColumnType(Types.CLOB, "varchar(MAX)");
      registerColumnType(Types.LONGVARCHAR, "varchar(MAX)");
      registerColumnType(Types.VARCHAR, "varchar(MAX)");
      registerColumnType(Types.VARCHAR, MAX_LENGTH, "varchar($l)");

//      registerColumnType(Types.BIGINT, "bigint");
//      registerColumnType(Types.BIT, "bit");

      registerFunction("row_number", new NoArgSQLFunction("row_number", new IntegerType(), true));

      // SQL Server 2008
      registerColumnType(Types.DATE, "date");
      registerColumnType(Types.TIME, "time");
      registerColumnType(Types.TIMESTAMP, "datetime2");

      registerFunction("current_timestamp", new NoArgSQLFunction("current_timestamp", new TimestampType(), false));
   }

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.