【Hibernate】——简介

来源:互联网 发布:手机淘宝拍摄脸部 编辑:程序博客网 时间:2024/06/07 07:41

         今天这篇文章主要介绍下Hibernate的核心接口和工作机制。    

一、什么是Hibernate

     Hibernate是ORM(objectRelational Mapping)实现中的一种,符合了面向对象的编码思想,传统的操作数据库,是将对象的属性一一取出,然后再将其赋值到数据库中所对应的列,这样破坏了面向对象的操作,而hibernate刚好解决了这一问题,将数据库中的操作数据转化成对象关系模型,这样在操作的时候,我们则对每个类进行操作,这样符合了面向对象的操作,下面看看是怎么实现的。

二、核心接口分别有以下几种

      1.Configuration

        它的主要作用是读取hibernate.cfg.xml文件。

       2. SessionFactory

         相当于hibernate的镜像,保存了一些关于对数据库的操作,比如说操作数据库的增删改查。

       3.Transaction

          数据库操作事物的接口

       4.Session

           类似于缓存,一般来说,操作数据先将其保存在Session中,然后再将其保存在数据库中

三、hibernate的配置文件

      以下用mysql数据库进行举例

      

<span style="font-family:KaiTi_GB2312;font-size:18px;"><!DOCTYPE hibernate-configuration PUBLIC"-//Hibernate/Hibernate Configuration DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration><session-factory><property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property><property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate_first</property><property name="hibernate.connection.username">root</property><property name="hibernate.connection.password">123456</property><property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property><property name="hibernate.show_sql">true</property><property name="hibernate.format_sql">true</property><mapping resource="com/bjpowernode/hibernate/User.hbm.xml"/></session-factory></hibernate-configuration></span>


      介绍了这么些,那我们是怎么样实现通过操作类,将其类中的数据写入数据库中的呢?请关注下一篇博客,

将具体介绍下具体的操作流程!

0 0
原创粉丝点击