Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Hibernate

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "how to use Hibernate". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Overview of Hibernate

Hibernate is a lightweight mapping framework

Mapping rules:

The class corresponds to the table

The properties of the class correspond to the fields of the table

The instance of the class corresponds to a specific record in the table

A class can correspond to multiple tables, and a table can correspond to a class.

Tables in DB can have no primary key, but the primary key field must be set in Object

The relationship between table and table (such as foreign key) in DB is mapped to the relationship between Object.

The number and name of attributes in Object can be different from the number and name of fields defined in the table

Briefly describe the advantages and disadvantages of hibernate

Advantages:

Simplifies the tedious coding of JDBC

Good support for object-oriented features

Good portability

Disadvantages:

Not suitable for situations that require a specific optimization mechanism for the database

Not suitable for large-scale batch data processing

A brief introduction to the comparison between Hibernate and mybatis

Compared with the ORM implementation of "SQL-Mapping" of MyBatis, the ORM implementation of Hibernate is more perfect, providing functions such as object state management, cascading operation and so on.

Completely object-oriented, statements have nothing to do with the database, developers do not need to pay attention to the generation of SQL, the development is simple, easy to modify, and the database is portable.

Due to the high degree of freedom of using SQL,MyBatis directly

Build Hibernate environment

Download the required jar file and import it into the file

Hibernate's official website http://hibernate.org

Hosting website https://sourceforge.net/projects/hibernate/files/

Recommended download: hibernate-distribution-3.6.10.Final-dist.zip

Note:

The Hibernate official website can be downloaded to a newer version, and other versions can be obtained through the hosting website.

Use log4j to log and download and add

Http://www.slf4j.org/dist/

Slf4j-log4j12-1.6.1.jar

Http://archive.apache.org/dist/logging/log4j/

Log4j-1.2.17.jar

Deploy jar files

Hibernate3.jar

The jar file in the lib\ required directory

Lib\ jpa\ hibernate-jpa-2.0-api-1.0.1.Final.jar

Mysql or Oracle database driven jar files

Write Hibernate configuration file

Used to configure database connections

Various features required at run time

It is generally named "hibernate.cfg.xml"

Create persistent classes and mapping files

Define persistent classes (also known as entity classes), real java.io.Serializable interfaces, and add default constructors

Configure the mapping file (* .hbm.xml)

Configure a mapping file to a hibernate.cfg.xml file

Take a specific user entity as an example:

That's all for the content of "how to use Hibernate". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report