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 integrate spring hibernate

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

Share

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

How to integrate spring hibernate, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Hibernate has a lot to learn, here mainly introduces Spring Hibernate, including the introduction of integrated Sample and other aspects.

one。 Introduction

Recently, I participated in the background software design and development of the audit system of a bank in North America. In addition to using Web Service, we integrated Spring and Hibernate to access database data through Spring's HibernateTemplate. It is well known that Hibernate is a widely used and powerful data persistence layer technology. On the other hand, as a dependency injection framework supporting IOC, Spring has the advantage of being able to integrate most of the mainstream technologies very well. In this article, we will discuss how to integrate Spring Hibernate.

II. Spring Hibernate Foundation

Before we actually get into integrating these two technologies, let's understand this integration requirement. We all know that Hibernate is a powerful ORM tool that sits between the application and the database. It enables applications to access data from various databases in an independent platform, and it is not necessary for applications to rely on low-level DBC details such as managing connections, dealing with statements and result sets. All the details of accessing a specific data source can be easily configured in the Xml file. Another advantage is that Hibernate and J2SE and J2EE applications are very compatible.

One of the problems with using Hibernate is that customer applications that use Hibernate Framework to access databases must rely on Hibernate APIs such as Configuration, SessionFactory and Session. These objects continue to spread in the application code. And the application code must maintain and manage these objects manually. But in the Spring environment, business objects can be configured with the help of IOC. In short, an object state can be separated from the application code. It means that it is now possible to use Hibernate objects as Spring Beans, and they can get all the convenience provided by Spring.

three。 Integrated Sample

We do not intend to study the various API integrated in the Spring package, we want to learn and understand these APIs through the example source code. The following sections cover each step of integrating Spring-Hiberante with a detailed explanation.

1. Create a database

The following application uses an Oracle database. The express version of Oracle10g can be downloaded for free from http://www.oracle.com/technology/products/database/xe/index.html. After installation, log in as an administrator and create a user schema,username and password, then log in as a user and run the following SQL statement in SQL command or SQL Script: create table Activitylog (id varchar (10), name varchar (20), taskcode varchar (3), tasktime timestamp); now an empty table has been created.

2.ActivityLog class

Now let's create code called Activitylog POJO to store data fetched from the Activitylog table, designed so that the column names of table 'Activitylog' will be mapped to variable names of the appropriate type of Java class Activitylog. It can be generated using the ant tool or plug-in. The complete code of the Activitylog class is listed below:

Package com.xxx.audit.pojo; public class Activitylog {private String id; private String name; private String taskcode; private Timestamp tasktime; public Activitylog () {} public String getId () {return id;} public void setId (String id) {this.id = id;} public String getName () {return name;} public void setName (String name) {this.name = name;} public String getTaskcode () {return taskcode } public void setTaskcode (String taskcode) {this.taskcode = taskcode;} public Timestamp getTasktime () {return tasktime;} public void setTasktime (Timestamp tasktime) {this.tasktime = tasktime;} public String toString () {return "Id =" + id + ", Name =" + name + ", Taskcode =" + taskcode + ", Tasktime =" + tasktime;}}

Note that the toString () method is rewritten for the display of the Activitylog object.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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