Hibernate synchronizer 3.1.9?

Source: Internet
Author: User

When the method in the DaO automatically generated by hibernate synchronizer 3.1.9 is used, a "session is closed." exception is reported.

For example, when the findbyname () method is used,

View the generatedCode, Found

Public java. util. List <mapping. User> findbyname (Java. Lang. string name ){
Return findfiltered ("name", name). List ();
}

The following method in _ baserootdao is finally called:

Protected criteria findfiltered (string propname, object filter, order ){
Session S = NULL;
Try {
S = getsession ();
Return findfiltered (S, propname, filter, order );
}
Finally {
Closesession (s );
}
}

(Note that the session is closed in finally)
When the list () method of criteria generated by this method is called, some code in the list () method checks that the session is closed and throws the above one.

Public list () throws hibernateexception {
Before ();
Try {
Return session. List (this );
}
Finally {
After ();
}
}

The List () method in the session:

Public list (criteriaimpl criteria) throws hibernateexception {
Errorifclosed ();
Checktransactionsynchstatus ();
String [] implementors = factory. getimplementors (criteria. getentityorclassname ());
Int size = implementors. length;
......

Errorifclosed ():

Protected void errorifclosed (){
If (closed ){
Throw new sessionexception ("session is closed! ");
}
}

The temporary solution is to remove the code for closing the session in finally above. ThenProgramRunning properly.

I am a beginner in hibernate. Please call us more. Thank you!

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.