hibernate basic configuration

1. The role of the orm framework:

Save the object data to the relational database, and read the data from the relational database table into the object

 

Second, hibernate provides powerful object and relational database mapping, powerful query function

 

Three, Hibernate application development steps -

Design entity class

1. Setter and getter methods

2. Public parameterless constructor

3. Properties of Object Identifiers

4. If the property is a collection type, the interface type List Set Map must be defined

5, can be serialized

 

Mapping file: **.hbm.xml

 

Database table creation: 

1. Generate ddl according to the object relationship mapping file and use the schemaExport work class:

configuration config = new configuration().configure(cfg);

SchemaExport se = new SchemaExport(config)

se.create(true,true);

 

2. Add in the hibernate configuration file

<property name = "hibernate.hbm2ddl.auto">create</property>

 

 

Fourth, use hibernate api for persistence operations

Operation process

1. Create an instance of sessionfactory: Corresponding to a data storage source, the characteristics of sessionfactory are thread-safe and heavyweight.

2. Obtaining session instances is thread-insecure, lightweight, and is called the first-level cache of hibernate. It is opened through sessionfactory and has nothing to do with httpsession.

3. Turn on transaction transaction, hibernate must control transaction when performing persistence operation

4. Use session instance for persistence operation

5. Submit the transaction 

6. Close the session

7. Both query and criterion are query interfaces of hibernate. Query wraps an hql query statement, and the criterion interface is more object-oriented.

 

 

 

 

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326612758&siteId=291194637