<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)  編輯  收藏 所屬分類: 數據庫
    主站蜘蛛池模板: 久久国产精品免费一区| 亚洲国产日产无码精品| 男人天堂2018亚洲男人天堂| 国产99久久久国产精免费| 在线免费观看色片| 亚洲毛片一级带毛片基地| av永久免费网站在线观看| 爱情岛论坛网亚洲品质自拍| 久久精品国产亚洲AV天海翼 | 污污网站免费观看| 亚洲精品专区在线观看| 337p日本欧洲亚洲大胆人人| 国产成人无码免费看视频软件 | 亚洲毛片无码专区亚洲乱| av永久免费网站在线观看| 永久免费av无码不卡在线观看| 另类免费视频一区二区在线观看| 国内少妇偷人精品视频免费| 日韩免费在线观看视频| 青草草色A免费观看在线| 亚洲的天堂av无码| 黄色三级三级免费看| 久久久精品视频免费观看 | 亚洲图片一区二区| 国产一区二区三区免费观在线| 亚洲av无码片vr一区二区三区| 亚洲国产精品综合久久久| 亚洲韩国—中文字幕| 亚洲av午夜福利精品一区| 亚洲精品无码久久久久去q| 亚洲一区二区三区在线观看精品中文 | 毛片免费在线观看网址| 91香蕉成人免费网站| 91香蕉国产线在线观看免费| a在线观看免费视频| 国产成人无码精品久久久免费| 一级A毛片免费观看久久精品| 一区二区三区免费高清视频| 一级毛片在线免费播放| 岛国岛国免费V片在线观看| 最近更新免费中文字幕大全|