Hibernate (Object-Oriented Database Operations) and hibernate object-oriented
JPA, java persistance api, java persistence layer interface, that is, some interfaces dealing with databases. The implementation is handed over to various vendors for implementation.
ORM, Object/Relation Mapping, Object/Relational Database ing. For object-oriented database operations, the underlying layer is still SQL statements.
Obtain the maven dependency of hibernate.
<Dependency> <groupId> org. hibernate </groupId> <artifactId> hibernate-core </artifactId> <version> 4.3.10.Final </version> </dependency> <! -- Both c3p0 and mysql require dependency --> <dependency> <groupId> mysql </groupId> <artifactId> mysql-connector-java </artifactId> <version> 5.1.31 </version> </dependency>
Hibernate is an excellent ORM implementation. For usage instructions, see.
The configuration file name is hibernate. cfg. xml, which is usually placed in the src directory. It uses c3p0 as the database connection pool.
<? Xml version = '1. 0' encoding = 'utf-8'?> <! DOCTYPE hibernate-configuration PUBLIC "-// Hibernate/Hibernate Configuration DTD 3.0 // EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
Common classes @ javax. persistence. Entity
Indicates that this class corresponds to an object in a table in the database.
@ Javax. persistence. Table
The name attribute of this annotation indicates which table the java class corresponds.
@ Javax. persistence. Id
Indicate that this field is the primary key in the database table.
@ Javax. persistence. Column
The name attribute of this annotation specifies which column of the field corresponds to the table. By default, mutual matching of the same name is performed.
@ Javax. persistence. Temporal
The database has many time types. The value TemporalType. TIMESTAMP indicates the TIMESTAMP.
@ Javax. persistence. Transient
When a pojo field is not in the table, you can add this comment to avoid errors.
HQLorg. hibernate. SharedSessionContract. createQuery (String queryString)
Create a query using the given hql statement.
List org. hibernate. Query. list ()
Returns the query result as a list.
Sample Code