Use of native SQL in hibernate+spring+struts causes oping JDBC Connection Connection pool resource extraction problem

Source: Internet
Author: User

The code has been playing for months.

Hibernatetemplate hibernatetemplate = Gethibernatetemplate ();
Sessionfactory sessionfactory = Hibernatetemplate.getsessionfactory ();
Session session = Sessionfactory.opensession ();
Query query = session.createsqlquery (HQL). addentity (Arguments.class);
list<arguments> list = Query.list ();
if (List.size () >0)
return list;

This section of code is used by hibernate original eco-SQL. Then this method is called several times later. will let the connection pool draw the light connection (own conjecture). ----------------If a great God can answer the question, where is the root?

The solution is to use

Hibernatetemplate.executefind (New Hibernatecallback () {
Public Object doinhibernate (org.hibernate.Session Session)
Throws Hibernateexception, SQLException {
Query query = session.createsqlquery (HQL). addentity (Object.class);
List<object> list =query.list ();
return list;
}

The proxy can be resolved by using an anonymous inner class.

Why is it? Is there a great God to answer it?

Use of native SQL in hibernate+spring+struts causes oping JDBC Connection Connection pool resource extraction problem

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.