Hibernate framework (i)--General introduction

Source: Internet
Author: User
Tags mysql database log4j

Hibernate, one of the three main SSH frameworks, is used to work with the DAO layer of the program and the database, which encapsulates the steps of JDBC, and it is easier and quicker for us to operate the database. With the hibernate framework, we can no longer write duplicate JDBC code, and we will not test repeatedly how our SQL statements are written. Here we need a simple configuration, call the framework to provide us with the method, you can complete the data additions and deletions, then hibernate is exactly what kind of framework. How to use it. Let's look at a knowledge system diagram of the Hibernate framework:



This blog, we come to summarize, hibernate macro understanding and environment building.


One, what is hibernate exactly.


Hibernate is a lightweight, metadata-based ORM framework:


1, metadata (meta data):d ATA about data (data), that is, describing an object's data, equivalent to the context of the object.


2, Lightweight: less resource-intensive, no intrusion. (In fact, I think this is relatively, if compared with ibatis, it into a heavyweight).


3,orm: (object Relation Mapping) mapping of a relational database

This is the focus of the Hibernate framework, which means that the entities in our program (beans, also called pojo) and the tables in the database are mapped. Java type and SQL type mapping, object-oriented design and relational database design mapping, so we just need to put more effort into the business, rather than the SQL database aspect.


4,pojo: (Plain ordinary Java object), plain Java objects that are unformatted, that is, the entity that is said above, and the simple class that the database does the mapping. Just put a new noun here.

All in all, Hibernate is the Pojo class of our database tables and programs mapped, the operation of the data is encapsulated, so that we do not have to make the database very proficient, we will be object-oriented programming can be, which greatly improve our programming efficiency, and the personal knowledge requirements are reduced. (Hibernate is designed to do this, but I think to better apply hibernate, better grasp the context of development, it is required that we have a higher ability, know its why)

Second, Environment construction:


1, as in the first few framework of the approximate process, we need to copy into the necessary jar package. The jar package is locked into a good enough principle, what to copy what, of course, some log output, unit testing is to better look at the framework and copied into the not necessary. Here is the demo with MySQL, so we used the MySQL driver jar package:

Antlr-2.7.6.jar (Generate SQL statement)

Asm.jar (Byte Code enhancement Tool Class)

C3p0-0.9.1.jar (data source connection pool component)

Cglib-2.1.3.jar (proxy component, inheritance-based)

Commons-collections-2.1.1.jar (Collection tool class components for efficient operation)

Commons-logging-1.0.4.jar (conversion component for log output)

Log4j-1.2.11.jar (log output component, more detailed and can control output format, and destination)

Dom4j-1.6.1.jar (XML parsing)

Ehcache-1.2.3.jar (Cache component)

Ejb3-persistence.jar (Specification jar package for persistent operation)

Hibernate3.jar (Core jar package for the framework)

Jta.jar (Global transaction Management)

Junit-3.8.1.jar (unit test)

Mysql-connector-java-3.1.13-bin.jar (MySQL database driver jar pack)

2. Introduce the configuration file:

Hibernate.cfg.xml Hibernate core configuration file (including database connection configuration, mapping file reading, etc.)

Log4j.properties log4j Log Output control file

User.hbm.xml mapping file (the user here only matches the user entity, and an entity class corresponds to a mapping file of this class.) )

3, the core configuration file Hibernate.cfg.xml writing:[HTML]  View plain  copy  print?

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.