1. persist entity domain objects directly through the JDBC API :
A, java.sql Common interfaces and classes:
DriverManager: Driver Manager, responsible for creating database connections.
Connection: Represents a database connection.
Statement: Responsible for executing SQL statements.
PreparedStatement: is responsible for executing SQL statements, with the functionality of predefined SQL statements.
ResultSet: The query result set for the code SQL query statement.
2 . Common ORM Middleware :
Hibernate\mybatis\toplink\torque\objectrelationbridge\frontiersuite\castor\freefrom\expresso\ Jrelationframework\vbsf\jgrinder
3.Hibernate Core Interface :
A,Configuration Class: Used to read Hibernate configuration files and generate Sessionfactory objects. The startup in Hibernate process, an instance of the configuration class first locates the location of the mapped document, reads the configuration, and then creates a The Sessionfactory object.
B,Sessionfactory Interface: Generates session instance factory. Sessionfactory actually plays a buffer in hibernate, which buffers hibernate's automatically generated SQL statements and some other mapping data, it also buffers some data that may be reused in the future.
C,Session Interface: Used to operate the PO. It has methods such as get (), load (), save (), update (), and delete () to load, save, update, and delete the PO. It is the core interface of hibernate. The Session object is non-thread safe, so in your design it is best to have a The thread creates only one session object.
D,Query Interface: To query the PO. It can be generated from the CreateQuery () method of the session. The query interface makes it easy to make queries to databases and persistent objects, which can be expressed in two ways: hql language or this SQL statements for the database. Queries are often used to bind query parameters, limit the number of query records, and ultimately perform query operations.
E,Criteria Interface : Thecriteria interface is very similar to the query interface, which allows you to create and execute object-oriented, standardized queries.
F, Transaction Interface : Used to manage hibernate transactions, its main methods are commit () and rollback (), which can be generated from the session's Begintrancation () method.
G,Callback interface : When a useful event occurs-for example, when a persistent object is loaded, stored, deleted, the Callback interface notifies hibernate to receive a notification message. interceptor,lifecycle, and Validatable interface.
H, Policy interface : When you feel that some of hibernate's features are inadequate, or if you have some flaws, you can develop your own strategy to replace it, and all you have to do is just inherit one of its policy interfaces and implement your new strategy.
Generation of primary keys (Identifiergenerator interface)
Native SQL language Support (dialect abstract class)
Buffering mechanism (cache and Cacheprovider interface)
JDBC Connection Management (ConnectionProvider interface)
Transaction management (Transactionfactory, Transaction, and Transactionmanagerlookup interfaces)
ORM policy (Classpersister interface)
Property access Policy (PropertyAccessor interface)
Creation of proxy objects (Proxyfactory interface)
I, the interface for extending hibernate : Usertype,compositeusertype
Iv. General steps for using hibernate :
A. Create the Hibernate configuration file.
B, create a persistence class.
C, create the object-relational mapping file.
D. Write code to access the database through the Hibernate API.
V. FIRST Hibernate program :
A, Hibernate.properties:
?
1 2 3 4 5 6 |
hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate. connection .driver_class=com.mysql.jdbc.Driver hibernate. connection .url=jdbc:mysql://localhost:3306/SAMPLEDB hibernate. connection .username=root hibernate. connection . password =root hibernate.show_sql= true |
B. Create a Persistence class:
C. Create object-relational mapping file:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<?xml version=
"1.0"
?> <!DOCTYPE hibernate-mapping
PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
>
<class
name
=
"mypack.Customer" table
=
"CUSTOMERS"
>
<id
name
=
"id" column
=
"ID" type=
"long"
>
<generator class=
"increment"
/>
</id>
<property
name
=
"name"
column
=
"NAME"
type=
"string" not
-
null
=
"true" />
<property
name
=
"email"
column
=
"EMAIL" type=
"string" not
-
null
=
"true" />
<property
name
=
"password"
column
=
"PASSWORD"
type=
"string" not
-
null
=
"true"
/>
<property
name
=
"phone"
column
=
"PHONE"
type=
"int" />
<property
name
=
"address"
column
=
"ADDRESS"
type=
"string" />
<property
name
=
"sex" column
=
"SEX"
type=
"character"
/>
<property
name
=
"married"
column
=
"IS_MARRIED"
type=
"boolean"
/>
<property
name
=
"description"
column
=
"DESCRIPTION"
type=
"text"
/>
<property
name
=
"image"
column
=
"IMAGE"
type=
"binary"
/>
<property
name
=
"birthday"
column
=
"BIRTHDAY" type=
"date"
/>
<property
name
=
"registeredTime" column
=
"REGISTERED_TIME"
type=
"timestamp"
/>
</class>
|
D. Write code to access the database through the Hibernate API: