hibernate是一个开源框架,它是对象关联关系映射的框架,它对jdbc做了轻量级的封装。
它的核心接口:
configuration:负责配置并启动hibernate,创建sessionFactory。
sessionFactory:负责初始化hibernate,创建session对象。
session:负责对持久化对象CRUD操作。
Transaction:负责事物相关的操作。
Query和Criteria接口:负责执行各种数据库查询。
<hibernate-configuration>
<!-- 数据源的配置 -->
<session-factory name="foo">
<property name="connection.url"></property>
<property name="connection.name"></property>
<property name="connection.password"></property>
<property name="connection.driver_class"></property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
</session-factory>
<!-- 导入映射文件 -->
<mapping resource="com/..../dao/User.hbm.xml">
</hibernate-configuration>
User.hbm.xml
<hibernate-mapping package="com....dao">
<class name="User" table="表名">
<id name="id" type="int" column="id">
<generator class="native"/>
</id>
<property name="name" type="string" column="name" length="10" not-null="true"/>
<property name="age" type="int" column="name" not-null="true"/>
....................
</class>
</hibernate-mapping>
它的核心接口:
configuration:负责配置并启动hibernate,创建sessionFactory。
sessionFactory:负责初始化hibernate,创建session对象。
session:负责对持久化对象CRUD操作。
Transaction:负责事物相关的操作。
Query和Criteria接口:负责执行各种数据库查询。
配置文件:
hibernate.cfg.xml<hibernate-configuration>
<!-- 数据源的配置 -->
<session-factory name="foo">
<property name="connection.url"></property>
<property name="connection.name"></property>
<property name="connection.password"></property>
<property name="connection.driver_class"></property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
</session-factory>
<!-- 导入映射文件 -->
<mapping resource="com/..../dao/User.hbm.xml">
</hibernate-configuration>
User.hbm.xml
<hibernate-mapping package="com....dao">
<class name="User" table="表名">
<id name="id" type="int" column="id">
<generator class="native"/>
</id>
<property name="name" type="string" column="name" length="10" not-null="true"/>
<property name="age" type="int" column="name" not-null="true"/>
....................
</class>
</hibernate-mapping>