分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

Hibernate

发布时间:2023-09-06 02:00责任编辑:彭小芳关键词:Hibernate

先放入门demo

hibernate的工作原理

 配置文件

对于 hibernate 的核心配置文件它有两种方式:
1. hibernate.cfg.xml
2. hibernate.properties

我们主要讲解的是 hibernate.cfg.xml 配置

1. 可以加载数据库相关信息

<property name="hibernate.connection.driver_class" >com.mysql.jdbc.Driver</property>

<property name="hibernate.connection.url" >jdbc:mysql:///hibernateTest</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的方言 -->

<property name="hibernate.dialect" >org.hibernate.dialect.MySQLDialect</property>

3.加载映射配置文件

<mapping resource="cn/itheima/domain/Customer.hbm.xml" />

对于hibernate.cfg.xml的其它配置信息可以参考下边文件里的hibernate.properties

hibernate.properties的配置也在下边文件里

配置文件

映射文件配置

文件名称为.hbm.xml

其主要作用是建立表与类的映射关系.

1.统一声明包名,这样在<class>中就不需要写类的全名.

<hibernate-mapping package="cn.itheima.domain"/>

Hibernate

原文地址:https://www.cnblogs.com/zyh186/p/9189882.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved