<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)  編輯  收藏 所屬分類: 數據庫
    主站蜘蛛池模板: 亚洲精品无码永久在线观看| 51视频精品全部免费最新| 欧洲精品成人免费视频在线观看| 亚洲另类激情综合偷自拍图| 免费视频精品一区二区| 国产美女无遮挡免费视频| 亚洲AV日韩AV无码污污网站| 在线观看免费a∨网站| 亚洲综合av一区二区三区| 大学生高清一级毛片免费| 亚洲一久久久久久久久| 夫妻免费无码V看片| 亚洲av色香蕉一区二区三区蜜桃| 日本特黄a级高清免费大片| MM1313亚洲国产精品| 亚洲天堂男人影院| 无人影院手机版在线观看免费| 中日韩亚洲人成无码网站| 午夜影视在线免费观看| 蜜芽亚洲av无码一区二区三区| 国产乱子伦精品免费女| 国产国产人免费人成成免视频| 在线精品亚洲一区二区三区| 国产在线精品免费aaa片| 亚洲欧洲精品国产区| 成人免费视频88| 又黄又大的激情视频在线观看免费视频社区在线| 免费观看四虎精品国产永久| 久久性生大片免费观看性| 久久久久亚洲AV片无码下载蜜桃 | 国产91色综合久久免费分享| 欧洲 亚洲 国产图片综合| 永久免费无码网站在线观看| 一级a性色生活片久久无少妇一级婬片免费放 | 亚洲人成片在线观看| 国产大片91精品免费观看男同| 一本到卡二卡三卡免费高| 亚洲an天堂an在线观看| 免费av欧美国产在钱| 和老外3p爽粗大免费视频| 久久精品亚洲精品国产色婷|