<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Sealyu

    --- 博客已遷移至: http://www.sealyu.com/blog

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks

    I found out today that MS Sql server seems to handle Unicode in a very special way. Instead of having some support a database or table level, each Unicode column have to be created as “national”. That is be either nchar, nvarchar or ntext.

    Ms SQL Server 2005 seems to go one step further by announcing future deprecation for ntext, text and image types.

    From Sql Server 2005 notes:

    ntext, text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.”

    When working with Hibernate it seems there is no dialect to handle Unicode integration properly. You have to get down and write a custom dialect that maps to the new data types.

    /**
    * Unicode support in SQL Server
    *
    * @author icocan
    */
    public class UnicodeSQLServerDialect extends SQLServerDialect {

    public UnicodeSQLServerDialect() {
    super();

    // Use Unicode Characters
    registerColumnType(Types.VARCHAR, 255, "nvarchar($l)");
    registerColumnType(Types.CHAR, "nchar(1)");
    registerColumnType(Types.CLOB, "nvarchar(max)");

    // Microsoft SQL Server 2000 supports bigint and bit
    registerColumnType(Types.BIGINT, "bigint");
    registerColumnType(Types.BIT, "bit");
    }
    }
    read more ...

    You have to write your own SQLServerDialect class, it looks something like this:
    publicclassSQLServerNativeDialectextendsSQLServerDialect{
         publicSQLServerNativeDialect(){
             super();
             registerColumnType(Types.VARCHAR,"nvarchar($l)");
             registerColumnType(Types.CLOB,"nvarchar(max)");
         }

        publicString getTypeName(int code,int length,int precision,int scale)throwsHibernateException{
            if(code !=2005){
                returnsuper.getTypeName(code, length, precision, scale);
            }else{
                return"ntext";
            }
        }
    }

    This class maps Hibernate's types to SQL types, so the class will map the nvarchar(max) SQL Data Type to Hibernate's CLOB data type.

    The getTypeName method is used to return "ntext" when Hibernate asks about the data type with code 2005 (which looks like it's the nvarchar(max) data type).

    Finally, you need to change your hibernate persistence dialect to this new SQLServerDialect class, which allows hibernate to translate data types into SQL data types.


    posted on 2010-11-29 18:49 seal 閱讀(692) 評論(0)  編輯  收藏 所屬分類: 數據庫
    主站蜘蛛池模板: 亚洲精品午夜无码专区| www亚洲精品少妇裸乳一区二区| 在线亚洲97se亚洲综合在线| 色噜噜狠狠色综合免费视频| 热99re久久精品精品免费| 亚洲精品久久久久无码AV片软件| 国产精品视频免费一区二区| 亚洲精品GV天堂无码男同| 国产精品视_精品国产免费| 精品国产日韩亚洲一区在线| 免费一级毛片正在播放| 久久99久久成人免费播放| 在线亚洲精品自拍| 日韩精品无码免费一区二区三区| 久久青青草原亚洲av无码app| 中文字幕在线日亚洲9| 免费无码黄十八禁网站在线观看| 亚洲乱码日产精品一二三| 四虎永久免费地址在线网站| 一级特黄a免费大片| 亚洲AV无码日韩AV无码导航| 91精品视频免费| 国产成人亚洲综合在线| 日韩一卡2卡3卡4卡新区亚洲| 久久青草免费91线频观看站街| 亚洲狠狠狠一区二区三区| 四色在线精品免费观看| 久久久精品国产亚洲成人满18免费网站| 亚洲欧洲美洲无码精品VA| 中文毛片无遮挡高潮免费| 亚洲国产成人AV网站| 亚洲桃色AV无码| 国国内清清草原免费视频99| 免费人成再在线观看网站| 亚洲成年轻人电影网站www| 在线播放免费人成视频在线观看| 极品美女一级毛片免费| 911精品国产亚洲日本美国韩国| 国产成人免费全部网站| 国产精品免费一区二区三区四区| 亚洲欧美乱色情图片|