java - Using ScheduledExecutorService to save(Entites), I get detached Entity passed to persist error -


i have curious error cant seem head around. need use scheduledexecutorservice pass survey entity created edited , saved new entity.

public void executescheduled(survey eventobject, long interval) {     hashmap<string, string> eventrrules = stringutils.extractserialdetails(eventobject.getvcalendarrrule());      long delay = 10000;      scheduledexecutorservice service = executors.newscheduledthreadpool(1);      runnable runnable = new runnable() {         private int counter = 1;         private int executions = integer.parseint(eventrrules.get("count"));         survey survey = eventobject;         public void run() {             string uid = eventobject.getuniqueeventid();             logger.info("surveycontroller - executescheduled - iteration: " + counter);             string serialuid = null;             if (counter == 1) {                 serialuid = uid + "-" + counter;             } else {                 serialuid = stringutils.removelastandconcatvar(eventobject.getuniqueeventid(), integer.tostring(counter));             }             if (++counter > executions) {                 service.shutdown();             }              survey.setuniqueeventid(serialuid);             try {             executecreatesurvey(survey);             } catch(exception e) {                 logger.debug("surveycontroller - executescheduled - exception caught: ");                 e.printstacktrace();             }         }     };      service.scheduleatfixedrate(runnable, delay, interval, timeunit.milliseconds); } 

when executecreatesurvey(survey) method run without scheduleexecutorservice, works flawlessly. yet when executed inside run() method, "detached entity passed persist" error each time save(survey) method run within executecreatesurvey() method....

the executecreatesurvey() method .save() method called:

public responseentity<?> executecreatesurvey(survey eventobject) {     mailservice mailservice = new mailservice(applicationproperties);      participant eventowner = participantrepositoryimpl.createorfindparticipant(eventobject.geteventowner());     eventobject.seteventowner(eventowner);      survey survey = surveyrepositoryimpl.createsurveyorfindsurvey((survey) eventobject);      // saves additional information if small errors (content     // errors,.. )     // occurs     string warnmessage = "";     list<participant> participants = new arraylist<participant>();     (participant participantdetached : eventobject.getparticipants()) {          // check if participant exists         participant participant = participantrepositoryimpl.createorfindparticipant(participantdetached);         participants.add(participant);          // create partsur if not existing (update case)         if (partsurrepository.findallbyparticipantandsurvey(participant, survey).isempty()) {             partsur partsur = new partsur(participant, survey);             partsurrepository.save(partsur);              try {                 mailservice.sendratinginvitationemail(partsur);                 surveyrepository.save(survey);             } catch (exception e) {                 // no special exception "security" reasons                 string errormessage = "error sending mail participant: " + e.getmessage() + "\n";                 warnmessage += errormessage;                 logger.warn("createsurvey() - " + errormessage);             }         }     }      // delete partsurs , answers removed participants     list<partsur> partsursforparticipantsremoved = partsurrepository.findallbyparticipantnotin(participants);     logger.warn("createsurvey() - participants removed: " + partsursforparticipantsremoved.size());     partsurrepositoryimpl.invalidatepartsurs(partsursforparticipantsremoved);      return new responseentity<>("umfrage wurde angelegt. warnungen: " + warnmessage, httpstatus.ok); } 

what reason this? have not been able find problem anywhere far.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -