IntelliJ IDEA配置 Hibernate连接Mysql8的hibernate.cfg.xml
2021/6/22 2:27:15
本文主要是介绍IntelliJ IDEA配置 Hibernate连接Mysql8的hibernate.cfg.xml,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
连接mysql8需要注意的是驱动driver和url以及dialect跟mysql5配置不同
1、driver
<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
2、url
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC</property>
这里要注意,xml文件中不能用&特殊符号,需要修改为 &
3、dialect
<property name="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</property>
贴上完整配置文件代码
<?xml version="1.0" encoding="UTF-8"?> <!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.driver_class">com.mysql.cj.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">root</property> <!-- 2、配置hibernate信息 --> <!--输出底层sql语句--> <property name="hibernate.show_sql">true</property> <!--输出底层sql语句格式--> <property name="hibernate.format_sql">true</property> <!--hibernate帮忙创建表配置 update:如果已经有表,更新,否则创建 --> <property name="hibernate.hbm2ddl.auto">update</property> <!--配置数据库方言 在mysql里面实现分页,关键字limit,只能使用在mysql里面 在oracle数据库,实现分页rownum 让hibernate框架识别不同的数据库语句 --> <property name="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</property> <!-- 3、把映射文件放到核心配置文件中 --> <mapping resource="Entity/User.hbm.xml"/> </session-factory> </hibernate-configuration>
这篇关于IntelliJ IDEA配置 Hibernate连接Mysql8的hibernate.cfg.xml的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-25MySQL报错Duplicate entry '0' for key 'PRIMARY'
- 2024-05-29阿里 Canal 实时同步 MySQL 增量数据至 ClickHouse 数据库
- 2024-05-24在Linux下管理MySQL的大小写敏感性
- 2024-04-26MySQL查出时间比实际晚8小时的解决方案
- 2024-04-01JPA不识别MySQL的枚举类型
- 2024-03-30mysql数据库表卡死解决方法
- 2024-03-15MySQL多数据源笔记5-ShardingJDBC实战
- 2024-03-11natural join mysql
- 2024-03-11关于VS2017,VS2015 中利用 EF使用Mysql 不显示数据源问题解决方案
- 2024-02-26mysql 阿里云xb后缀备份文件恢复-icode9专业技术文章分享