<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 閱讀(686) 評論(0)  編輯  收藏 所屬分類: 數據庫
    主站蜘蛛池模板: 久久久亚洲精品蜜桃臀| 成人免费网站在线观看| 久久久久亚洲精品中文字幕| 极品色天使在线婷婷天堂亚洲| 午夜视频在线在免费| 亚洲码和欧洲码一码二码三码 | 亚洲AV无码一区二区乱子仑| 成人免费一级毛片在线播放视频| 亚洲国产午夜电影在线入口| 日本最新免费网站| 一本色道久久88—综合亚洲精品 | 国产亚洲综合网曝门系列| 一个人免费观看视频在线中文| 国产亚洲av片在线观看18女人| 你懂的免费在线观看| 亚洲AV美女一区二区三区| 最近中文字幕免费完整| 亚洲精品国产精品国自产网站 | 日韩视频在线精品视频免费观看| 色噜噜亚洲男人的天堂| 四虎永久在线精品免费影视 | jzzjzz免费观看大片免费| 亚洲高清国产拍精品26U| h片在线免费观看| 色九月亚洲综合网| 亚洲中文字幕无码不卡电影| 免费人成黄页在线观看日本| 99热亚洲色精品国产88| 亚洲av成人一区二区三区在线观看| 黄色视频在线免费观看| 亚洲美女aⅴ久久久91| 免费特级黄毛片在线成人观看| 成年网站免费入口在线观看| 亚洲av无码一区二区三区网站 | 免费**毛片在线播放直播 | 精品一区二区三区免费毛片爱| 国产亚洲中文日本不卡二区| 老司机亚洲精品影视www| 18未年禁止免费观看| 免费毛片毛片网址| 久久亚洲精品人成综合网|