SSH integration, "sessionfactory" or "hibernatetemplate" is required exception

Source: Internet
Author: User
From Cai yanru blog (http://www.cnblogs.com/cxy0703)
The first problem is caused by hibernatedaosupport. All Dao in the program are inherited from hibernatedaosupport, while hibernatedaosupport needs to inject sessionfactory or hibernatetemplate. Therefore, an exception occurs when "sessionfactory" or "hibernatetemplate" is, however, exceptions still occur after sessionfactory bean configuration is added to the spring configuration file.
Later I looked at the solution on the Internet, because spring. if default-autowire = "byname" is not added to XML, the instantiated sessionfactory cannot be found during the annotation, but an empty sessionfactory is injected, and the error is reported during hibernate check. The annotation can be correctly used after Bean injection is added to the spring configuration file byname.
<Beans
Xmlns = "http://www.springframework.org/schema/beans"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xmlns: AOP = "http://www.springframework.org/schema/aop"
Xmlns: Tx = "http://www.springframework.org/schema/tx"
Xmlns: context = "http://www.springframework.org/schema/context"
Xsi: schemalocation ="
Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
Http://www.springframework.org/schema/aop
Http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
Http://www.springframework.org/schema/tx
Http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context-2.5.xsd"
Default-autowire = "byname" default-Lazy-init = "true">
 
The general reason is that the default-autowire = "byname" statement is missing ". This bird problem is confusing for one afternoon.
 
 
When default-autowire = "byname" is not added, I can add the following code. However, this is only to locate the cause of the problem and is not the final solution, the final solution is to add the above sentence to the configuration file.
Import com. yhqxgl. Dao. tdeptdao;
Import com. yhqxgl. entity. tdept;
@ Repository ("tdeptdaoimpl ")
@ Transactional
Public class tdeptdaoimpl extends hibernatedaosupport implements tdeptdao {
Public Boolean add (tdept Dept ){

This. gethibernatetemplate (). Save (Dept );
Return true;
}
@ Autowired
Public void setsessionfactoryoverride (sessionfactory)
{
Super. setsessionfactory (sessionfactory );
}
}
 
Sessionfactory has not been injected into hibernatedaosupport, so this. gethibernatetemplate () = NULL here.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.