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

What is Hibernate Sample?

2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what is Hibernate Sample". In daily operation, I believe many people have doubts about what Hibernate Sample is. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what is Hibernate Sample?" Next, please follow the editor to study!

The application we are going to build is very simple, just using hibernate3.0 to manipulate a table.

Software environment:

1.Eclipse3.1.2

2.MyEclipse4.1.0

3.MySql Server 5.0

4.MySql Java Connector J 5.0.4

5.hibernate3.0 Core Libraries

6.hibernate3.0 Advanced Libraries

The creation of the entire application is completed as follows:

1. Create a new mysql schema named hibernatetest

two。 Create a table called User with the following statement:

CREATE TABLE `hibernatetest`.`User` (`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT

`name` VARCHAR (45) NOT NULL, `sex` CHAR NOT NULL, `age`

TINYINT UNSIGNED NOT NULL, PRIMARY KEY (`id`)

)

ENGINE = InnoDB

3. Open the DB Browser view of MyEclipse and select New on the right-click options menu (Context Menu). , pop-up Database

Profile dialog box, which is used to create a new Profile and fill in the following information:

◆ Profile Name: localhost_mysql_profile

◆ Driver: open the Configure database driver link and configure the jdbc driver. We just need to join the JDBC driver of MySql Connector J.

◆ URL: jdbc: mysql://127.0.0.1:3306/hibernatetest

◆ User Name: user name

◆ Password: password

After creating the profile, try to connect to the database and succeed.

4. Create a new Java project named Hibernate Sample in Eclipse

◆ creates a directory called config to place the hibernate.cfg.xml

◆ creates a directory called mappings to place the mapping file

5. In the right-click options menu of the Hibernate Sample project, select MyEclipse- > Add Hibernate Capabilities. This will bring up a dialog box for Hibernate Support for MyEclipse:

The step of ◆ > * is to select the package to be added to the project. We check both the Core and Advanced packages of Hibernate3.0.

Whether or not to create hibernate.cfg.xml in the second step of ◆, we set configuration folder to src\ config

The third step of ◆ is to specify the database connection details (specify database connection details). We just need to call it localhost_mysql_profile, because we have already set it up before.

Step 4 of ◆ asks you if you want to create a SessionFactory, which is actually a SessionFactory provided by Hibernate for

Manage the class of Session, which ensures that Session is * in each separate thread, and we create a class called cn.com.test.Hibernate Sample.factory.HibernateSessionFactory; through the above four steps, the project now has the packages and configuration files required for hibernate.

At this point, the study of "what is Hibernate Sample" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Development

Wechat

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

12
Report