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

怼烎@ 2022-04-14 03:48 338阅读 0赞
  1. <!DOCTYPE hibernate-configuration PUBLIC
  2. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  3. "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  4. <hibernate-configuration>
  5. <session-factory>
  6. <!-- 一、 数据库连接的参数配置 -->
  7. <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/app?useUnicode=true&characterEncoding=utf8</property>
  8. <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  9. <property name="hibernate.connection.username">root</property>
  10. <property name="hibernate.connection.password">root</property>
  11. <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  12. <!-- 二、 hibernate其他常用配置 -->
  13. <property name="hibernate.show_sql">true</property><!--
  14. <property name="hibernate.format_sql">true</property>
  15. --><property name="hibernate.hbm2ddl.auto">update</property>
  16. <!-- 三、加载映射文件
  17. <mapping resource="cn/itcast/a_status/Employee.hbm.xml"/>-->
  18. <mapping resource="entity/User.hbm.xml"/>
  19. </session-factory>
  20. </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,&不能直接写,应改为:&不然会报错(在xml配置文件中配置数据库utl时,要使用&的转义字符也就是&)

数据库连接报错**:对实体 “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(解决时差问题)

发表评论

表情:
评论列表 (有 0 条评论,338人围观)

还没有评论,来说两句吧...

相关阅读