hibernate 遇到的配置错误

原文链接: hibernate 遇到的配置错误

上一篇: spring 配置

下一篇: Hibernate5 配置C3P0连接池

一个可以使用的配置文件,主要是jdbc字符串,然后在导入jar包时,注意版本问题,在这里卡了一天。。。。。。。。。。

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>

        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <!--数据库url地址  -->
        <property name="hibernate.connection.url">
            <!--jdbc:mysql://localhost:3306/stu_mgr?characterEncoding=UTF-8;useSSL=false-->
            <![CDATA[jdbc:mysql://localhost:3306/stu_mgr?characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT]]>
        </property>

        <property name="hibernate.connection.username">root</property>
        <!--密码  -->
        <property name="hibernate.connection.password">root</property>

        <!--
            org.hibernate.dialect.MySQLDialect
            org.hibernate.dialect.MySQLInnoDBDialect
            org.hibernate.dialect.MySQLMyISAMDialect
            使用 MySQL5InnoDBDialect 可新建表
        -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

        <!--
        执行DDL的类别:
        create:每次都删除新建
        update:存在就修改,不存在就新建
        -->
        <property name="hbm2ddl.auto">update</property>
        <!--是否显示SQL语句  -->
        <property name="hibernate.show_sql">true</property>
        <!--是否格式化SQL语句  -->
        <property name="hibernate.format_sql">true</property>
        <!--启用getCurrentSession,默认未启用-->
        <property name="hibernate.current_session_context_class">thread</property>

        <!--加载配置文件-->
        <!--<mapping resource="stu.hbm.xml"></mapping>-->
    </session-factory>
</hibernate-configuration>

SSL警告


Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. 

 
加上 useSSL=false 

Unknown system variable 'query_cache_size'

这个错是 数据库驱动版本和 数据库不一致导致的。解决方法如下:


根据自己的数据库版本去这个地址选择合适的驱动版本 https://mvnrepository.com/artifact/mysql/mysql-connector-java 比如我的数据库版本是 8.0.11,那么对应的驱动为: <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.11</version> </dependency>


 

timeZone乱码

这是由于数据库和系统时区差异所造成的,在jdbc连接的url后面加上serverTimezone=GMT即可解决问题,如果需要使用gmt+8时区,需要写成GMT%2B8,否则会被解析为空。再一个解决办法就是使用低版本的MySQL jdbc驱动,5.1.28不会存在时区的问题。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值