hibernate的配置出现的错误问题汇总

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
    	<!-- 一、 数据库连接的参数配置 -->
    	<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/app?useUnicode=true&amp;characterEncoding=utf8</property>
    	<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    	<property name="hibernate.connection.username">root</property>
    	<property name="hibernate.connection.password">root</property>
    	<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    
    	<!-- 二、 hibernate其他常用配置 -->
    	<property name="hibernate.show_sql">true</property><!--
    	<property name="hibernate.format_sql">true</property>
    	--><property name="hibernate.hbm2ddl.auto">update</property>
    	
    	<!-- 三、加载映射文件
    	<mapping resource="cn/itcast/a_status/Employee.hbm.xml"/>-->
    	<mapping resource="entity/User.hbm.xml"/> 
    	
    </session-factory>
</hibernate-configuration>

1,url要加上utf-8,不加会出现

Unknown initial character set index '255' received from server. Initial client character 

解决:https://blog.csdn.net/txwtech/article/details/80787886

2,&不能直接写,应改为:&amp;不然会报错(在xml配置文件中配置数据库utl时,要使用&的转义字符也就是&amp;)

数据库连接报错:对实体 "characterEncoding" 的引用必须以 ';' 分隔符结尾

3.还要加上时区

jdbc:mysql://localhost:3306/houses?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC

4.新版本的驱动是

com.mysql.cj.jdbc.Driver

serverTimezone=Asia/Shanghai(解决时差问题)

猜你喜欢

转载自blog.csdn.net/weixin_42533856/article/details/84404312