Before we get to know hibernate, let's review the traditional JDBC access to the database. The focus is on analyzing the flaws in JDBC access, how are these flaws thought and resolved in hibernate?
JDBC Main object
Drivemanager: Represents the driver manager and is responsible for creating a database connection
Connection: On behalf of the database connection
Statement: Responsible for executing SQL statements
Preparestatement: Inheriting statement, responsible for executing SQL statements, with predefined SQL statement functionality
Results: A query result set that represents a SQL query statement
JDBC Access Step
1. Load and register driver JDBC Driver
2. Establish database connection
3, create the statement object, and prepare to execute the SQL statement
4. Execute SQL statement
5, turn off statement and connection objects in turn
JDBC Flaw
1, programmers must understand the Java language, but also understand the SQL language, in order to write database access code
2, the program code embedded a large number of string form point of SQL statements, reducing the independence and readability of program code
3, the program code and relational database structure together, weaken the program code independence and reliability. Example: The database table modifies a field name, and the SQL statements involved in the program code are also modified
4, programmers need to understand, objects and tables, attributes and fields corresponding relationship. So programmers need to be familiar with the object model, and need to understand the relationship database, but also to understand the corresponding relationship between the two, so programmers can not follow the full object-oriented thinking to write program code
Once you understand the drawbacks of JDBC access to the database, we'll do a simple example and analyze the hibernate steps and how to solve the drawbacks of JDBC for this example.