How to Use the find method of gethibernatetemplate

Source: Internet
Author: User

Why use the find method of gethibernatetemplate?

Generally, we have two options to access the database:

Getsession (). createquery ("from Area ");

Gethibernatetemplate (). Find ("from area );

 

Generally, we have two options to access the database:

Getsession (). createquery ("from Area ");

Gethibernatetemplate (). Find ("from area );

Pass the test: (online search is to be tested)

Call getsession (). createquery ("fromusers") cyclically ");

Gethibernatetemplate (). Find ("from users );

1000 results getsession () soon reported that the connection could not be established.

However, gethibernatetemplate cannot be used up.

Through the background observation, using getsession will leave a lot of SQL * Net message from client connections in the database. After the test is terminated, the connection is automatically released.

Gethibernatetemplate uses a connection from start to end. Does getsession () Fail to automatically release the connection?

So I cyclically call getsession (). createquery ("fromusers ");

Gethibernatetemplate (). Find ("from users );

Five times it was found that when the front-end program ends, the five connections of getsession were immediately released.

If the connection is automatically released after the previous 1000 tests are terminated, it means that getsession () will automatically release the connection.

Conclusion:

(1) Both getsession () and gethibernatetemplate can automatically release connections (of course, your configuration must be correct ), however, getsession in a thread will get many sessions (that is, many sessions and connections), which may cause the database connection to exceed the upper limit. Therefore, gethibernatetemplate is recommended.

(2) If some statements cannot be implemented using gethibernatetemplate, you can use gethibernatetemplate.exe cute to use the hibernatecallback callback interface. In addition, you can set the allowcreate value of hibernatetemplate to true and disable the session in finally. You can also pass true as a parameter to the super. getsession (...) method to get the session. This is also possible, that is, the trouble.

Note: The Defined name must be consistent with the executed parameter.

Otherwise:

Error: Note

 

Error message corresponding to different names:

Tip:

 

Tip:

 

 

 

 

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.