[Transfer] Bind Dao to Spring SessionFactory

zhaozj2021-02-16  61

Bind DAO to Spring SessionFactory

In Spring, it is already integrated with Hibernate. When we need to call a Vo corresponding to the DAO to operate VO, we must bind the DAO to Spring has defined the sessionFactory, then DAO gains session to complete various operations to VO.

Hibernate has been configured in Spring's basic operating environment, which supports Hibernate, which is configured in the default directory web -inate.xml, which is mainly configured between Spring and Hibernate. And Hibernate's operation is done through configuration information in this file. If Hibernate is running, the * .hbm.xml, etc.

ApplicationContext-hibernate.xml contains the following configuration basic information:

2 Configure the database connection pool used by Spring, you need to have the name of the database connection pool established in the application server

Such as:

java: comp / env / jdbc / gsgesmysql

2 Configure basic information of database connections (including drivers, database connectivity, user names, and passwords, including setting Hibernate which type of database)

Such as:

/web-inf/classes/jdbc.properties

The basic information of JDBC.Properties is as follows:

-------------------------------------------------- -------------------------------------------------- -----------------------------

Jdbc.driverclassName = com.mysql.jdbc.driver

JDBC.URL = JDBC: mysql: //211.155.200.38: 3306 / gsgesdb? Useunicode = true & characterencoding = UTF-8

JDBC.USERNAME = GSGES

jdbc.password = GSGES

Hibernate.diaforct = net.sf.hibernate.dialect.mysqldiaLect

-------------------------------------------------- -------------------------------------------------- -----------------------------

2 Configuring Hibernate related * .hbm.xml file

Employee.hbm.xml

$ {hibernate.diaforct}

among them:

The value of $ {hibernate.diaalect} is the value read in JDBC.Properties

2 The DAO and registration of DaoImpl registered in the bean management pool, the reference to these registered beans are distinguished by the ID attribute of the bean identifier, and the DaoIMPL is a good contact with SessionFactory. When you directly in the controller can pass the DaoIMPL registered in the Bean Manager, you can complete the operation of VO, if you create a new DaoImpl in the controller. It will not be able to get the session in the sessionFactory, will throw an exception of the empty pointer

PropAgation_required, readonly

PropAgation_required, readonly

PropAgation_required, readonly

Propagation_required

Set the DaoIMPL registered by the Bean Manager in the controller:

Open the "Gsges_Servlet.xml" file set by the controller

SelegrowForm

Foundation.SeleGrow

user.home

Note:

SELEGROWDAO is associated with the SELEGROWDAOIMPL registered in the Bean Manager to associate with the SelegrowTarget, and then complete the operation of VO by creating a SelegrowDao instance in the controller.

When you register a DAO in the Bean Manager through the above manner, there must be a Private Dao instance attribute, and there is a set and get method for that attribute so that the manager will set the controller. The DAO instance is an object instance of the bean manager, and then you can perform the DAO instance directly to the VO in the controller.

转载请注明原文地址:https://www.9cbs.com/read-18546.html

New Post(0)