목차

Hibernate & MS SQL Server

NVARCHAR Dialect 매핑

Entity에 NVARCHAR 컬럼 선언을 하려면

SELECT 결과 컬럼에 NVARCHAR 등이 있을 경우에 해석을 위한 Dialect 추가 설정

package com.nhl.dao;
import java.sql.Types;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.type.StandardBasicTypes;
 
public class SQlServerDBDialect extends SQLServerDialect {
 
public SQlServerDBDialect() {  super();
        registerHibernateType(Types.NCHAR, StandardBasicTypes.CHARACTER.getName()); 
        registerHibernateType(Types.NCHAR, 1, StandardBasicTypes.CHARACTER.getName());
        registerHibernateType(Types.NCHAR, 255, StandardBasicTypes.STRING.getName());
        registerHibernateType(Types.NVARCHAR, StandardBasicTypes.STRING.getName());
        registerHibernateType(Types.LONGNVARCHAR, StandardBasicTypes.TEXT.getName());
        registerHibernateType(Types.NCLOB, StandardBasicTypes.CLOB.getName());
 
} }