-->
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.  [ 4 posts ] 
Author Message
 Post subject: SQLServer 2000 Unicode Dialect
PostPosted: Fri Apr 29, 2005 9:48 am 
Beginner
Beginner

Joined: Tue Sep 21, 2004 4:04 pm
Posts: 25
Location: Oldsmar, FL
There are a couple of things (IMHO) "wrong" with the SQLServerDialect that comes with Hibernate 2.1.8 plus I wanted to use Unicode characters so I created this SQLServer2000UnicodeDialect.

SQL Server 2000 supports BIGINT and BIT which the 2.1.8 SQLServerDialect does not, maybe this was just a left over from Sybase or maybe based on an earlier version of SQL Server.
I would hope that this gets changed in future releases of Hibernate.

The other thing in this dialect is the use of nvarchar, nchar, and ntext to support Unicode characters.

Note I also use and highly recommend the jTDS driver when using SQL Server.

Code:
package my.hibernate.dialect;

import java.sql.Types;
import net.sf.hibernate.dialect.SQLServerDialect;

public class SQLServer2000UnicodeDialect extends SQLServerDialect
{

    public SQLServer2000UnicodeDialect ()
    {
        super();
       
        // Use Unicode Characters
        registerColumnType( Types.VARCHAR, "nvarchar($l)" );
        registerColumnType( Types.CHAR, "nchar(1)" );
        registerColumnType( Types.CLOB, "ntext" );
       
        // Microsoft SQL Server 2000 supports bigint and bit
        registerColumnType( Types.BIGINT, "bigint" );
        registerColumnType( Types.BIT, "bit" );

        // From SQLServerDialect.java,v 1.10 2005/02/22 14:05:52
        registerColumnType( Types.VARBINARY, "image" );
        registerColumnType( Types.VARBINARY, 8000, "varbinary($l)" );
    }

}


I donate the following to the Hibernate project.

Thanks for the great work you do.
[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 29, 2005 11:09 am 
Regular
Regular

Joined: Tue Nov 23, 2004 7:42 am
Posts: 82
Location: London, England
You don't need an additional dialect, just change the column types in the database. We did this with no problems.

I see your point though. Unless you read the SQL Server documentation you wouldn't know that text, varchar, etc. do not support unicode characters.

However, the same can be said of Postgres and MySQL. When you create the database/tables you need to explicitly say which character set you wish to use if you don't want the default. The only database DBMS I've worked with that lets you use Unicode characters without any additional faffing about is Oracle.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 29, 2005 11:14 am 
Beginner
Beginner

Joined: Tue Sep 21, 2004 4:04 pm
Posts: 25
Location: Oldsmar, FL
You do need the modified dialect if you use the SchemaExport facility (which we do).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 29, 2005 11:17 am 
Regular
Regular

Joined: Tue Nov 23, 2004 7:42 am
Posts: 82
Location: London, England
Maybe so.

We have a SQL file for the schema we run now. It's more convenient.


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

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.