<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 閱讀(685) 評論(0)  編輯  收藏 所屬分類: 數據庫
    主站蜘蛛池模板: 国产亚洲美日韩AV中文字幕无码成人| 麻豆亚洲AV成人无码久久精品 | 亚洲精品免费在线| 亚洲精品无码久久不卡| 成年在线观看网站免费| 日本在线看片免费| 一级毛片不卡免费看老司机| 亚洲欧美日韩综合久久久久| 综合自拍亚洲综合图不卡区| 亚洲小说区图片区另类春色| 狠狠久久永久免费观看| 91精品成人免费国产片| 国产精品免费AV片在线观看| 一个人看的在线免费视频| 色偷偷噜噜噜亚洲男人| 亚洲人配人种jizz| 亚洲综合综合在线| 亚洲AV无码专区国产乱码4SE| 亚洲一本大道无码av天堂| 国产伦一区二区三区免费| 永久免费av无码不卡在线观看| 久热免费在线视频| 免费国产污网站在线观看| eeuss影院ss奇兵免费com| 黄色片网站在线免费观看| 亚洲av乱码一区二区三区按摩| 亚洲国产精品综合久久20| 亚洲一级毛片视频| 亚洲国产成人精品无码区在线秒播 | 男女污污污超污视频免费在线看| 亚洲欧美日韩自偷自拍| 亚洲av无码一区二区三区天堂| 亚洲伊人久久大香线蕉结合| 亚洲第一男人天堂| 亚洲日韩精品国产3区| 亚洲欧洲专线一区| 亚洲av永久无码天堂网| 久久精品国产亚洲AV未满十八| 亚洲精品无码专区| 真正全免费视频a毛片| 三年片在线观看免费观看大全中国|