Hibernate additions, deletions and modifications
1. First, we need to know what Hibernate is.
Hibernate is a lightweight ORMapping object. Mainly used to achieve the mapping between Java and database tables, in addition to providing data query and data acquisition methods.
It can greatly reduce the time of manual use of SQL and JDBC to process data during development, and liberate 95% of the tasks of programmers.
2. What is ORM Object-Relational-Mapping Object Relational Mapping
ORM: It maps to database tables through Java objects. It can complete the operation of database tables by manipulating Java objects. (If you're using Dbutils, you need to write sql statements in Java classes, but ORM doesn't.)
Hibernate is a complete ORM framework that generates the underlying SQL only by manipulating objects.
Next, go directly to the theme:
First look at the basic process of using hibernate! Here's a simple flow chart
1. Create projects:
Create a web project with myeclipse
2. Import hibernate-related shelving packages into projects
Step 3: Configure hibernate
Create a new XML file under the src directory named hibernate.cfg.xml (of course, you may not call this name, but you need to modify the code accordingly). Copy the following:
Configure hibernate.cfg.xml<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <!-- Configuring Session Factory hibernate Core Management Database Connection Pool --> <session-factory> <!-- 1.Configure database connection parameters --> <!-- 1.1 To configure jdbc Four basic connection parameters --> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">root</property> <property name="hibernate.connection.url">jdbc:mysql:///hibernateexec</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <!-- 1.2 To configure hibernate Dialects in use --> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <!-- 2.Configure other related properties --> <!-- 2.1 Automatic table building --> <property name="hibernate.hbm2ddl.auto">update</property> <!-- 2.2 Output in log sql --> <property name="hibernate.show_sql">true</property> <!-- 2.3 Format sql --> <property name="hibernate.format_sql">true</property> <!-- Open transaction --> <property name="hibernate.connection.autocommit">true</property> <!-- To configure c3p0 Database connection pool --> <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> <property name="hibernate.c3p0.min_size">5</property> <property name="hibernate.c3p0.max_size">50</property> <property name="hibernate.c3p0.timeout">120</property> <property name="hibernate.c3p0.idle_test_period">3000</property> <!-- 3.Load the mapping file --> <mapping resource="com/study/model/Customer.hbm.xml"/> </session-factory> </hibernate-configuration>