Hibernate配置mysql数据库方言问题

在ssh架构和mysql数据库使用过程中,遇到了如下错误:

      org.hibernate.MappingException: No Dialect mapping for JDBC type: xxx

解决步骤:

1.更改hibernate的配置文件:由原来的:

hibernate.connection.driverClass=com.mysql.jdbc.Driver
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

(ps:MySQL 5.5及以上版本用这个方言,MySQL 5.5以下的貌似用org.hibernate.dialect.MySQLInnoDBDialect)
hibernate.connection.url=jdbc:mysql://localhost:3306/xxxx......
hibernate.connection.userName=xxxx
hibernate.connection.password=xxxx

改为:

hibernate.connection.driverClass=com.mysql.jdbc.Driver
hibernate.dialect=com.xxx.xxxx.util.DialectForInkfish(ps:此处是新建的Java文件的路径)
hibernate.connection.url=jdbc:mysql://localhost:3306/xxxx......
hibernate.connection.userName=xxxx
hibernate.connection.password=xxxx

2.新建Java文件,内容如下:

package com.xxx.xxxx.util;

import java.sql.Types;

import org.hibernate.Hibernate;
import org.hibernate.dialect.MySQL5Dialect;

public class DialectForInkfish extends MySQL5Dialect {

    public DialectForInkfish() {
        super();
        registerHibernateType(Types.LONGVARCHAR, 65535, "text");
        registerHibernateType(Types.DECIMAL, Hibernate.BIG_DECIMAL.getName());
        registerHibernateType(-1, Hibernate.STRING.getName());
    }
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值