Hibernate--Overview

Hibernate introduction:
ORM: Object/Relation Mapping, object-relational mapping, is by mapping Java objects to database tables, and by manipulating Java objects, you can complete operations on data tables.

hibernate: is an open source relational database ORM framework, a solution for the persistence layer of JavaEE applications, which provides addition, deletion, modification, and query operations for relational databases.

Advantages:
Hibernate encapsulates the code for JDBC access to the database, which greatly simplifies the tedious and repetitive code of the data access layer.
Hibernate is a mainstream persistence framework based on jdbc and an excellent orm implementation, which greatly simplifies dao Layer Coding Work
Hibernate uses java's reflection mechanism
Hibernate's performance is very good because it is a lightweight framework. The flexibility of the mapping is excellent. It supports many relational databases, ranging from one-to-one to many-to-many complex relationships

Writing process:
0. Import jar package
1. Create database and table
2. Write javabean and mapping file (mapping between objects and tables --> ORM)
3. Write core configuration file
4. Test, use api

jar package:
hibernate-distribution-3.6.10.Final\ hibernate3.jar
hibernate-distribution-3.6.10.Final\ \lib\required all, indicating that
hibernate-distribution-3.6.10.Final\ lib\jpa hibernate is required for jpa Support
database driver: mysql-connector-java-5.1.22-bin.jar

Mapping file:
1. File name: xxx.hbm.xml (same name and package as javabean)
2. Add constraint: hibernate3.jar-->org.hibernate—>hibernate-mapping-3.0dtd
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    " http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd ">
Mapping relationship:
<hibernate-mapping>
 <class name="cn .itcast.a_hello.User" table="t_user">
  <id name="uid">
   <!-- Primary key generation strategy-->
   <generator class="native"></generator>
  </id>
  <property name ="username"></property>
  <property name="password"></property>
 </class>
</hibernate-mapping>

Core configuration file:
1. Configuration file name: hibernate.cfg.xml
2. Location: src (classpath classpath)
3. Add constraints: hibernate3-->org.hibernate--->hibernate-configuration-3.0dtd
<!DOCTYPE hibernate-configuration PUBLIC
 "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
 " http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd ">
Configuration content:
<hibernate-configuration>
 <session -factory>
  <!-- Basic 4 items-->
  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="hibernate.connection.url">jdbc: mysql://localhost:3306/h_db</property>
  <property name="hibernate.connection.username">root</property>
  <property name="hibernate.connection.password">1234</property>
  <!-- Mapping file must be added to main configuration file-->
  <mapping resource="cn/itcast/a_hello/User.hbm.xml "/>
 </session-factory>
</hibernate-configuration>

Architecture:
 PO objects: Persistent Objects, persistent objects, hibernate is used to operate persistent objects, each persistent object has a mapping file
 VO value object value object, generally used for web layer
 BO business object business object, generally used for service Layer
 PO Persistent object, generally used for dao layer
--- comprehensive name: JavaBean
 OID: Each PO object has a unique identifier, which is used by hibernate to distinguish PO objects.
 Java distinguishes between objects: the addresses are different, if two objects are new, java is different.
 hibernate po object: use OID to distinguish, in time new two objects, as long as the OID value is the same, hibernate considers it to be an object.
 OID is used to store the primary key value in the table.

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326508035&siteId=291194637