sqlserver2008 使用ntext类型,hibernate查询报错 :No Dialect mapping for JDBC type: -9
或者 No Dialect mapping for JDBC type: -16等等,可以重写方言,让文本映射为String,参考下面代码
public class SQLServerCustomDialect extends SQLServer2008Dialect{
public SQLServerCustomDialect() {
super();
registerHibernateType(1, "string");
registerHibernateType(-9, "string");
registerHibernateType(-16, "string");
registerHibernateType(3, "double");
registerHibernateType(Types.CHAR, StandardBasicTypes.STRING.getName());
registerHibernateType(Types.NVARCHAR, StandardBasicTypes.STRING.getName());
registerHibernateType(Types.LONGNVARCHAR, StandardBasicTypes.STRING.getName());
registerHibernateType(Types.DECIMAL, StandardBasicTypes.DOUBLE.getName());
}
XML
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.yzsl.bean" ></property>
<property name="hibernateProperties">
<value>
<!-- hibernate.dialect=org.hibernate.dialect.SQLServer2008Dialect -->
hibernate.dialect=com.yzsl.util.SQLServerCustomDialect
hibernate.show_sql=true
hibernate.jdbc.fetch_size=50
hibernate.jdbc.batch_size=50
hibernate.connection.autocommit=true
hibernate.connection.release_mode=auto
hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
javax.persistence.validation.mode=none
</value>
</property>
</bean>