SqlServer 异常类型:
public final static int BIT
=
-7;
public final static int TINYINT
=
-6;
public final static int SMALLINT =
5;
public final static int INTEGER
=
4;
public final static int BIGINT
=
-5;
public final static int FLOAT
=
6;
public final static int REAL
=
7;
public final static int DOUBLE
=
8;
public final static int NUMERIC
=
2;
public final static int DECIMAL
=
3;
public final static int CHAR
=
1;
public final static int VARCHAR
=
12;
public final static int LONGVARCHAR
=
-1;
public final static int DATE
=
91;
public final static int TIME
=
92;
public final static int TIMESTAMP
=
93;
public final static int BINARY
=
-2;
public final static int VARBINARY
=
-3;
public final static int LONGVARBINARY
=
-4;
public final static int NULL
=
0;
public final static int OTHER
= 1111;
public final static int JAVA_OBJECT
=2000;
public final static int DISTINCT
= 2001;
public final static int STRUCT
=2002;
public final static int ARRAY
=2003;
public final static int BLOB
= 2004;
public final static int CLOB
= 2005;
public final static int REF
= 2006;
public final static int DATALINK = 70;
public final static int BOOLEAN = 16;
public final static int ROWID = -8;
public static final int NCHAR = -15;
public static final int NVARCHAR = -9;
public static final int LONGNVARCHAR = -16;
public static final int NCLOB = 2011;
public static final int SQLXML = 2009;
org.hibernate.MappingException: No Dialect mapping for JDBC type: -9
查阅资料,这个是由于JAVA对应数据库类型映射问题,-9是NVARCHAR 类型映射不了,
根据自己的方言加上:
RDBMS方言
DB2 | org.hibernate.dialect.DB2Dialect |
DB2 AS/400 | org.hibernate.dialect.DB2400Dialect |
DB2 OS390 | org.hibernate.dialect.DB2390Dialect |
PostgreSQL | org.hibernate.dialect.PostgreSQLDialect |
MySQL | org.hibernate.dialect.MySQLDialect |
MySQL with InnoDB | org.hibernate.dialect.MySQLInnoDBDialect |
MySQL with MyISAM | org.hibernate.dialect.MySQLMyISAMDialect |
Oracle (any version) | org.hibernate.dialect.OracleDialect |
Oracle 9i/10g | org.hibernate.dialect.Oracle9Dialect |
Sybase | org.hibernate.dialect.SybaseDialect |
Sybase Anywhere | org.hibernate.dialect.SybaseAnywhereDialect |
Microsoft SQL Server | org.hibernate.dialect.SQLServerDialect |
SAP DB | org.hibernate.dialect.SAPDBDialect |
Informix | org.hibernate.dialect.InformixDialect |
HypersonicSQL | org.hibernate.dialect.HSQLDialect |
Ingres | org.hibernate.dialect.IngresDialect |
Progress | org.hibernate.dialect.ProgressDialect |
Mckoi SQL | org.hibernate.dialect.MckoiDialect |
Interbase | org.hibernate.dialect.InterbaseDialect |
Pointbase | org.hibernate.dialect.PointbaseDialect |
FrontBase | org.hibernate.dialect.FrontbaseDialect |
Firebird | org.hibernate.dialect.FirebirdDialect |
public class SqlServer2008Dialect extends MySQL5Dialect{
public SqlServer2008Dialect(){
super();
registerHibernateType(Types.DECIMAL, Hibernate.BIG_DECIMAL.getName());
registerHibernateType(-1, Hibernate.STRING.getName());
}
}
在属性文件配置:
<property name="hibernate.dialect" value="XXXXX(自己的包名.SqlServer2008Dialect)" />
就行了。