spring - Getting LazyInitializationException within in a @Transactional method -
i’m getting exception when access method controller:
{"status":"failure","exception":"lazyinitializationexception","exceptionmessage":"failed lazily initialize collection of role: org.mainco.subco.lessonplan.domain.lessonplan.classrooms, not initialize proxy - no session","errormessage":"failed lazily initialize collection of role: org.mainco.subco.lessonplan.domain.lessonplan.classrooms, not initialize proxy - no session"}
controller:
@autowired private thirdpartyservice m_thirdpartysvc; … @requestmapping(value = "/launch", method = requestmethod.get) @transactional public string launchlti(final @requestparam string assignmentid, final model model, final httpservletrequest request, final httpservletresponse response, final principal principal) throws invalidkeyexception, unsupportedencodingexception, nosuchalgorithmexception { final subcoauthenticationuser auth = (subcoauthenticationuser) ((authentication) principal).getprincipal(); string nextpage = null; final user user = m_usersvc.findbyid(auth.getid()); // provision assignment in thirdparty if not done final assignment assmt = m_lessonplandao.getassignment(assignmentid); if (!assmt.issenttothirdparty()) { m_thirdpartysvc.sendassignment(assignmentid); } // if
is @transactional
annotation unnecessary? since have on @service
class…
@service @transactional public class thirdpartyserviceimpl implements thirdpartyservice { @override public void sendassignment(final string assignmentid) { final assignment assignment = m_lessonplandao.getassignment(assignmentid); if (isthirdpartyassignment(assignment)) { final string thirdpartypromptid = assignment.gettocitem().getthirdpartypromptid(); // gather teacher id final lessonplan lessonplan = m_lessonplandao.getlessonplan(assignment.getlessonplan().getid()); final string teacherid = lessonplan.getownerid(); // gather students have been assigned assignment final list<classroom> classes = lessonplan.getclassrooms(); // send 1 request each class assignment (final classroom classroom : classes) {
the error occurs on for (final classroom classroom : classes)
line. have @transactional
everywhere, yet i’m getting lazyinitializationexception
. why? , how create transaction can run method?
i’m using spring 3.2.11.release, hibernate 4.3.6.final, , jpa 2.1 on jboss 7.1.3.final. if upgrading of these solve problem, let me know.
the @tranactional boundary being respected application during runtime. can find out calling: transactionsynchronizationmanager#isactualtransactionactive()
add code print out value of above method. if false, maybe need make sure component scan
isn't set right.
example: <context:component-scan base-package="com.application.dao" />
this totally miss classes in com.application.service
package.
Comments
Post a Comment