No Dialect mapping for JDBC type: 7

网上搜的

No Dialect mapping for JDBC type: 7
I got this error while I was working with hibernate and SQL Server. Following are the findings I came across. Hope this helps you too rectify this error.

Following questions are relevant to understand this clearly.

What is jdbc type 7?
java.sql.Type.REAL : It is a constant in the java programming language, that identifies SQL type REAL.
Value of this constant is 7. This is the above mentioned jdbc type 7.

What is dialect?
Dialect is the type of the database that hibernate is going to use. Following are the commonly used dialects. These are the subclasses of the org.hibernate.dialect.Dialect for specific databases.

org.hibernate.dialect.HSQLDialect
org.hibernate.dialect.Oracle9Dialect
org.hibernate.dialect.MySQLDialect
org.hibernate.dialect.SQLServerDialect
org.hibernate.dialect.FirebirdDialect
What cause this error to occur?
The database may contain a table with field of datatype real. Hibernate dialect SQLServerDialect doesnot understand this type. So we need to explicitly convert this real type to one that dialect can understand. One way to achieve this is to write a subclass of org.hibernate.dialect.SQLServerDialect.


package co.nr.javaalert.hibernate.dialect;
import java.sql.Types;
public class SubSQLServerDialect extends org.hibernate.dialect.SQLServerDialect{
public SQLServerDialectForBilling() {
super();
registerColumnType(Types.REAL,"number($p,$s)");
registerHibernateType(Types.REAL,"double");
}
}

registerColumnType() method register a type name for a given type code. This step register sql column data type NUMBER(precision,scale) to Types.REAL. Then register this Types.REAL with a data type that can understand hibernate. The recommended Java mapping for the sql REAL type is as a Java float.

Use this subclass instead of org.hibernate.dialect.SQLServerDialect in hibernate.cfg.xml.

Reference
SQL dialects reference/Data structure definition/Data types/Numeric types
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值