<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)  編輯  收藏 所屬分類: 數據庫
    主站蜘蛛池模板: 亚洲国产综合91精品麻豆| 亚洲熟女乱色一区二区三区| 久久精品国产亚洲AV高清热| 色综合久久精品亚洲国产| 97无码人妻福利免费公开在线视频| 波多野结衣免费在线观看| 精品国产日韩亚洲一区| 亚洲欧美日韩一区二区三区| 99久久人妻精品免费一区| 久久久久久久亚洲精品| 国产日韩久久免费影院| 国产又粗又长又硬免费视频| 亚洲成人免费网站| 国产情侣久久久久aⅴ免费 | 亚洲综合在线另类色区奇米| 亚洲另类无码一区二区三区| 国产成人免费高清在线观看| 日韩精品无码免费视频| 日本高清免费中文字幕不卡| 亚洲成a人片在线观看中文!!!| 日本三级2019在线观看免费| 99ri精品国产亚洲| 免费无码黄十八禁网站在线观看 | 久久不见久久见中文字幕免费 | 91av免费在线视频| 国产三级免费电影| 亚洲男同gay片| 亚洲国产一级在线观看| 精品亚洲视频在线| 在线观看永久免费视频网站| 日韩精品无码永久免费网站| 亚洲视频在线观看视频| 久久w5ww成w人免费| 久久精品a亚洲国产v高清不卡| 免费无码AV片在线观看软件| 国产美女视频免费观看的网站| 亚洲国产成人精品不卡青青草原| 怡红院免费的全部视频| 亚洲乱码日产一区三区| 今天免费中文字幕视频| 亚洲人成网站18禁止|