Converting spring LocalSessionFactoryBean to hibernate sessionfactory

Source: Internet
Author: User


[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<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"
Xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
Http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd ">


<! -- SessionFactory Transaction ************************************* ***** -->
<Bean id = "sessionFactory"
Class = "org. springframework. orm. hibernate3.LocalSessionFactoryBean">
<Property name = "configLocation"
Value = "classpath: hibernate. cfg. xml">
</Property>
</Bean>
--------------------------
</Beans>
<? Xml version = "1.0" encoding = "UTF-8"?>
<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"
Xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
Http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd ">
 
 
<! -- SessionFactory Transaction ************************************* ***** -->
<Bean id = "sessionFactory"
Class = "org. springframework. orm. hibernate3.LocalSessionFactoryBean">
<Property name = "configLocation"
Value = "classpath: hibernate. cfg. xml">
</Property>
</Bean>
--------------------------
</Beans>


Q:

Org. springframework. orm. hibernate3.LocalSessionFactoryBean;
This type does not have the getCurrentSession method at all.
The sessionFactory in productDAO is org. hibernate. SessionFactory. How is the intermediate type converted?
After trying to save it to the database, I couldn't figure out the type conversion. I think LocalSessionFactoryBean didn't implement the SessionFactory interface either? Www.2cto.com
Is it the getObject () method of LocalSessionFactoryBean?

A:
That's it! LocalSessionFactoryBean implements org. springframework. beans. factory. factoryBean interface. If spring implements org during assembly. springframework. beans. factory. the FactoryBean interface uses the FactoryBean # getObject () method to assemble the returned objects. For more information, see the following document.
If you want to get the LocalSessionFactoryBean instance, add '&' to the front of the id. In your configuration file, add BeanFactory. getBean ('& sessionFactory') obtains the instance of LocalSessionFactoryBean.
Author: Tender001
 

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.