打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Hibernate
<?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 元素用于配置Hibernate中的属性            键:值           -->          <!-- hibernate.connection.driver_class : 连接数据库的驱动  -->        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>

<!-- hibernate.connection.username : 连接数据库的用户名 --> <property name="hibernate.connection.username">root</property>

<!-- hibernate.connection.password : 连接数据库的密码 --> <property name="hibernate.connection.password">123</property>

<!-- hibernate.connection.url : 连接数据库的地址,路径 --> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernatedemo</property>

<!-------------------------------------------------------------------------------->

<!-- show_sql: 操作数据库时,会 向控制台打印sql语句 --> <property name="show_sql">true</property>

<!-------------------------------------------------------------------------------->

<!-- format_sql: 打印sql语句前,会将sql语句先格式化 --> <property name="format_sql">true</property>

<!-------------------------------------------------------------------------------->

<!-- hbm2ddl.auto: 生成表结构的策略配置 update(最常用的取值): 如果当前数据库中不存在表结构,那么自动创建表结构. 如果存在表结构,并且表结构与实体一致,那么不做修改 如果存在表结构,并且表结构与实体不一致,那么会修改表结构.会保留原有列. create(很少):无论是否存在表结构.每次启动Hibernate都会重新创建表结构.(数据会丢失) create-drop(极少): 无论是否存在表结构.每次启动Hibernate都会重新创建表结构.每次Hibernate运行结束时,删除表结构. validate(很少):不会自动创建表结构.也不会自动维护表结构.Hibernate只校验表结构. 如果表结构不一致将会抛出异常. --> <property name="hbm2ddl.auto">update</property>

<!-------------------------------------------------------------------------------->

<!-- 数据库方言配置 org.hibernate.dialect.MySQLDialect (选择最短的) --> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

<!-------------------------------------------------------------------------------->

<!-- hibernate.connection.autocommit: 事务自动提交 --> <property name="hibernate.connection.autocommit">true</property>

<!-------------------------------------------------------------------------------->

<!-- 将Session与线程绑定=> 只有配置了该配置,才能使用getCurrentSession --> <property name="hibernate.current_session_context_class">thread</property>

<!-------------------------------------------------------------------------------->

<!-- 引入ORM 映射文件 填写src之后的路径 --> <mapping resource="com/itheima/a_hello/User.hbm.xml"/> </session-factory></hibernate-configuration>
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
【Hibernate总结系列】hibernate.cfg.xml配置 - 阿蜜果 - Bl...
Hibernate的配置文件
hibernate官方文档(介绍hbm.xml配置的)
hibenate连接mysql及配置中的hbm2ddl.auto
Hibernate运行原理
Hibernate中SessionFactory配置
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服