Connecting to SQL Server using Hibernate

How to connect to the Sql Server database by using Hibernate in Netbeans 6.7.1? Please advice.

The dialect is disabled for me.

  • Tricky SQL Query for rolling credits
  • Date Conversion Issue MS Access to SQL Server
  • Sql: Get Attributes by joining 3 tables
  • Transactions breaking when using SP_ExecuteSQL
  • Implicit data conversion from string to int in sql server
  • Most recent date from the below table
  • more name attributes in Table
  • The multi-part identifier could not be bound in ms sql server database
  • How do I map a BigDecimal in Hibernate so I get back the same scale I put in?
  • Hibernate Query runs slow in the system, but fast when run directly
  • Which API takes higher priority over registerColumnType and registerHibernateType?
  • Hql query optimization - return indexed id or the whole object
  • 2 Solutions collect form web for “Connecting to SQL Server using Hibernate”

    For SQL Server 2000 and 2005, you should use SQLServerDialect (that should be preferred over SybaseDialect that will be deprecated).

    I can’t verify how NetBeans Hibernate wizard behave with SQL Server but, according to this tutorial:

    When you create a Hibernate configuration file using a wizard you specify the database connection by choosing from a list of database connection registered with the IDE. When generating the configuration file the IDE automatically adds the connection details and dialect information based on the selected database connection.

    So, my question is: did you register a database connection for your SQL Server database? If not, go to Services, add a New Driver (right click on the Drivers node) for your SQL Server JDBC driver and add a New Connection (right click on the Databases node) with the right URL for your database.

    For anyone using Hibernate with SQL Server – our customized dialect may help: http://www.componentix.com/blog/5/improved-hibernate-dialect-for-microsoft-sql-server

    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)");
        }
    }
    
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.