網上搜的
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
No Dialect mapping for JDBC type: 7
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
java --四種權限修飾符
Mr_VanGogha
2020-06-19 08:15:13
java --System類的常用方法
Mr_VanGogha
2020-06-19 08:15:13
一個實例理解Java Reference
Chungtow-Leo
2020-06-16 02:18:43
移植到jboss發生的jsp錯誤
iteye_21032
2020-02-24 05:01:04
Tomcat5.5區別5.0配置
iteye_21032
2020-02-24 05:01:04
一例spring嵌套事務
iteye_21032
2020-02-24 05:01:04
轉一個spring下LOG4j配置
iteye_21032
2020-02-24 05:01:04
SVN使用手記
iteye_21032
2020-02-24 05:01:04
Java流與文件操作
商云
2020-02-23 12:51:42
Eclipse3.7默認字體修改-幫你找回Courser-New字體
商云
2020-02-23 12:51:42
圖解析SQL語句中JOIN操作
商云
2020-02-23 12:51:42
Java語言對對象引用的4種方式
商云
2020-02-23 12:51:42
Java 線程池的原理與實現
商云
2020-02-23 12:51:42
JAVA 多線程和併發基礎面試問答
商云
2020-02-23 12:51:42
java實現中文轉化爲拼音與簡稱
商云
2020-02-23 12:51:42