Hibernate (Object-Oriented Database Operations) and hibernate object-oriented

Source: Internet
Author: User

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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.