SSH2 DAO注入sessionfactory的方式汇总
方法一:在spring配置文件中,为继承HibernateDaoSupport的DAO注入sessionFactory Spring为Hibernate的DAO提供工具类:HibernateDaoSupport。该类主要提供如下两个方法,方便DAO的实现: public final HibernateTemplate getHibernateTemplate() public fina
方法一:在spring配置文件中,为继承HibernateDaoSupport的DAO注入sessionFactory
Spring为Hibernate的DAO提供工具类:HibernateDaoSupport。该类主要提供如下两个方法,方便DAO的实现: public final HibernateTemplate getHibernateTemplate()
public final void setSessionFactory(SessionFactory sessionFactory)
其中,setSessionFactory方法用来接收Spring的ApplicationContext的依赖注入,可接收配置在Spring的SessionFactory实例,getHibernateTemplate方法则用来根据刚才的SessionFactory产生Session,最后生成HibernateTemplate来完成数据库访问。
典型的继承HibernateDaoSupport的DAO实现的代码如下:
public class PersonDAOHibernate extends HibernateDaoSupport implements PersonDAO
{
//采用log4j来完成调试时的日志功能
private static Log log = LogFactory.getLog(NewsDAOHibernate.class);
//返回全部的人的实例
public List getPersons()
{
//通过HibernateTemplate的find方法返回Person的全部实例
return getHibernateTemplate().find("from Person");
}
/**
* 根据主键返回特定实例
* @ return 特定主键对应的Person实例
* @ param 主键值
public News getPerson(int personid)
{
return (Person)getHibernateTemplate().get(Person.class, new Integer(personid));
}
/**
* @ person 需要保存的Person实例
*/
public void savePerson(Person person)
{
getHibernateTemplate().saveOrUpdate(person);
}
/**
* @ param personid 需要删除Person实例的主键
* /
public void removePerson(int personid)
{
//先加载特定实例
Object p = getHibernateTemplate().load(Person.class, new Integer(personid));
//删除特定实例
getHibernateTemplate().delete(p);
}
}
可以与前面的PersonDAOHibernate对比,会发现代码量大大减少。事实上,DAO的实现依然借助于HibernateTemplate的模板访问方式,只是,HibernateDaoSupport将依赖注入SessionFactory的工作已经完成,获取HibernateTemplate的工作也已完成。该DAO的配置必须依赖于SessionFactory,具体的配置如下:
/p>
"http://www.springframework.org/dtd/spring-beans.dtd">

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



As a modern programming language, Go language plays an important role in development. The Go language provides some built-in time functions and structures to make time processing more convenient. In this article, we will introduce some commonly used time processing methods in the Go language. time.Now() We can use the time.Now() function to get the current time: now:=time.Now()fmt.Println(now) output: 2019-06-131

Chrome will automatically record the URLs that have been entered in the address bar, and will automatically "associate query content" in the future. But many times we don't need some URLs, how to delete them? The editor often encounters this problem. Addresses that have been entered before will be blocked in front of commonly used addresses, resulting in the need to select several times to enter the desired website. I have looked for how to delete it at least three times because... I forget it every time. In the address bar shortcuts of Chrome's official help Chrome keyboard shortcuts, the delete shortcut key is clarified: ▍Windows deletes the address bar association content. Press the down arrow key to highlight the corresponding content, and then press the Shift+Delete key ▍macOS deletes the address Bar association content click down

The win10 input method has made great progress compared with previous system versions, and has many very useful functions. It is also very smooth to use overall and has the function of memory typing. However, some users already have their own input methods that are good to use. Now, if you want to delete the built-in win10 input method, how do you delete the win10 input method? Today I will tell you the details about how to delete the win10 input method. How to delete the input method in win10 1. Press [Win+i] to open the settings interface, and click on the "Time and Language" option. 2. Click "Region and Language" and click the "Options" button under "Chinese" on the right. 3. Click the "Microsoft Pinyin Alphabet" option and the "Delete" button will appear.

The win7 system is Microsoft's traditional operating system and has many practical functions, such as the function of win7 system restore points. By setting a restore point in win7, you can restore the system to the restore point in win7 to achieve the purpose of system repair. How to set restore point in win? The following editor will teach you how to set a restore point in win7. How to set a restore point in win7 1. Find the desktop shortcut, right-click and select Properties. 2. After entering the property settings, select Advanced System Configuration. 3. Select the system maintenance option in the pop-up system properties box. 4. Click to create a restore point now for the controller with system protection turned on. 5. Add a description of the restore point, then click Create, wait patiently for a while, the restore point is successfully established, and then click Close. You can restore the system next time.

These shortcuts can be used for a variety of different things on iPhone> In today's dynamic and fast-moving world, where the pursuit of efficiency and convenience takes center stage, the Shortcuts app on iPhone stands out as a very Powerful tool. It's designed to simplify and speed up daily tasks, significantly increasing productivity. This app is incredibly adaptable, enabling users to automate mundane, repetitive actions that consume precious time. Additionally, it provides tools to tailor personalized commands to individual needs and preferences. What's particularly noteworthy about the Shortcuts app is its integration with Apple's smart assistant, Siri. This feature allows the use of intuitive speech

The xp system can be said to be a computer system that Microsoft released a long time ago. Currently, very few people are using it. The key is to use it on old computers. Many netizens want to upgrade the xp system to win7, but they don’t know how to upgrade the xp system to win7. .The actual operation steps will be demonstrated below. 1. Download and install the three-step software for beginners and open it. Select the win7 system and click to reinstall immediately. 2. Wait for the tool to automatically download the win7 system. 3. Reinstall the Windows system online immediately after downloading, please follow the prompts. 4. After the installation is completed, you can choose to restart immediately. 5. Enter the run menu bar and select the second item XiaoBaiPE-MSDNOnlineIns

As the Go language becomes increasingly popular in the Internet industry, more and more developers are beginning to get involved in this language. In the Go language, type conversion is also one of the common programming operations. This article will introduce some common type conversion methods. Type assertion Type assertion is an operation that converts an interface type to another type. In Go language, type assertion can be made using the following syntax: value,ok:=interface{}.(type) where value represents the converted value, o

What are the signal processing methods in Go language? Go language is an efficient, concise programming language with native concurrency capabilities. It is widely used in network programming, distributed systems, cloud computing and other fields. In Go language, inter-process communication is implemented through pipes and signals. This article will introduce the use of signals and their processing methods in the Go language. Signals Overview A signal is a mechanism used by the operating system to send asynchronous events to processes. In Unix/Linux operating systems, signals are often used to notify processes of certain
