Spring + Hibernate Framework

Source: Internet
Author: User

It's been a long time since I used the spring framework, and it's been struts2+hibernate4 to build Web projects, and lately, to learn something about spring, spring is the most widely used framework now, and will work in this industry, so it's necessary to learn.

The spring framework is added first and can be run correctly;

The hibernate framework is then added in a separate generation of hibernate.cfg.xml, using the default DAO file rather than the DAO file style under the spring framework;

After the frame is added, the hibernate frame can be used alone when the spring frame is used alone, but there is a problem when running the Web project, and the console response is a datasource problem, searching the internet for a bit, When you add code to Spring-mvc.xml, the Web project runs. Reference Link: http://blog.csdn.net/zxygww/article/details/45914193

Add code:

<!--handling DataSource errors --
<bean id= "sessionfactory" class= "Org.springframework.orm.hibernate4.LocalSessionFactoryBean" >
<property name= "Configlocation" >
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<bean id= "datasource" class= "Org.springframework.jdbc.datasource.DriverManagerDataSource"/>
<bean id= "TransactionManager" class= "Org.springframework.orm.hibernate4.HibernateTransactionManager" >
<property name= "sessionfactory" ref= "Sessionfactory" ></property>
<property name= "DataSource" ref= "DataSource" ></property>
</bean>

Wherein,classpath:hibernate.cfg.xml refers to: Hibernate.cfg.xml file in src root directory

It seems that the convergence of the spring framework and the Hibernate framework still needs to be improved.

Spring + Hibernate Framework

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.