2017-11-22 34 views
2

은 페이지 생성과 관련하여 Quartz Job in Conluence에 큰 문제가 있습니다.예약 된 작업과의 Confluence에서 UnUniqueObjectException이 발생했습니다

QUARTZ 작업 클래스 :

@ComponentImport 
private final SpaceManager spaceManager; 
@Autowired 
private final GeneralConfig config; 
@Autowired 
private final PageCreator pageCreator; 
@ComponentImport 
private final PageManager pageManager; 

@Autowired 
public ReportingPluginJob(GeneralConfig config, SpaceManager spaceManager, PageCreator pageCreator, 
     PageManager pageManager) { 
    this.config = config; 
    this.spaceManager = spaceManager; 
    this.pageCreator = pageCreator; 
    this.pageManager = pageManager; 
} 

private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(ReportingPluginJob.class); 

@Override 
public void execute(JobExecutionContext jec) throws JobExecutionException { 

    Collection<String> keys = spaceManager.getAllSpaceKeys(SpaceStatus.CURRENT); 

    String parentPageName = config.getSchedulerWeeklyParentPageName(); 

    for (String key : keys) { 

     Page parentPage 
       = pageManager.getPage(key, parentPageName); 

     if (parentPage != null) { 
      LOG.debug("Creating weekly report for space " + key); 
      long pageId = parentPage.getId(); 
      try { 
       pageCreator.createEazyBiReport(key, pageId); 
      } catch (ApplicationException e) { 
       LOG.error("FAILED TO CREATE A REPORT FOR SPACE " + key + " with error: " + System.lineSeparator() 
         + e.getMessage()); 
      } 

     } 

    } 

} 

페이지 생성 클래스 :

Space space = spaceManager.getSpace(spaceKey); 

    if (page != null) { 
     page.setTitle(pageTitle); 
     page.setSpace(space); 
     page.setVersion(1); 
     page.addLabelling(new Labelling(label, page.getEntity(), AuthenticatedUserThreadLocal.get())); 
     page.setCreator(AuthenticatedUserThreadLocal.get()); 
     page.setCreationDate(new Date()); 
     Page parent = pageManager.getPage(parentId); 
     if (parent != null) { 
      parent.addChild(page); 
     } 
    } 
     pageManager.saveContentEntity(page, DefaultSaveContext.builder().suppressNotifications(true).build()); 
     attachmentProvider.attachExcelFileToPage(page); 

미친 저를 몰고 마지막으로 예외 :

org.springframework.dao.DuplicateKeyException: A different object with the same identifier value was already associated with the session : [com.atlassian.confluence.spaces.Space#31653891]; nested exception is org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [com.atlassian.confluence.spaces.Space#31653891] 
at org.springframework.orm.hibernate5.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:259) 
at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:362) 
at org.springframework.orm.hibernate5.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:326) 
at org.springframework.orm.hibernate5.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:704) 
at com.atlassian.confluence.core.persistence.hibernate.HibernateObjectDao.saveRaw(HibernateObjectDao.java:207) 
at com.atlassian.confluence.pages.persistence.dao.hibernate.CachingPageDao.saveRaw(CachingPageDao.java:157) 
at com.atlassian.confluence.core.DefaultContentEntityManager.saveContentEntity(DefaultContentEntityManager.java:150) 
at com.atlassian.confluence.pages.DefaultPageManager.saveContentEntity(DefaultPageManager.java:1388) 
at sun.reflect.GeneratedMethodAccessor2132.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) 
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) 
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) 
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
at com.atlassian.spring.interceptors.SpringProfilingInterceptor.invoke(SpringProfilingInterceptor.java:16) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
at com.atlassian.confluence.util.profiling.ConfluenceMonitoringMethodInterceptor.invoke(ConfluenceMonitoringMethodInterceptor.java:34) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) 
at com.sun.proxy.$Proxy105.saveContentEntity(Unknown Source) 
at sun.reflect.GeneratedMethodAccessor2132.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at com.atlassian.plugin.util.ContextClassLoaderSettingInvocationHandler.invoke(ContextClassLoaderSettingInvocationHandler.java:26) 
at com.sun.proxy.$Proxy253.saveContentEntity(Unknown Source) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) 
at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:56) 
at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:60) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:70) 
at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:53) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
at org.eclipse.gemini.blueprint.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:57) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) 
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) 
at com.sun.proxy.$Proxy2863.saveContentEntity(Unknown Source) 
at com.censored.atlassian.plugins.service.PageCreator.createEazyBiReport(PageCreator.java:128) 
at com.censored.atlassian.plugins.service.ReportingPluginJob.execute(ReportingPluginJob.java:64) 
at com.atlassian.confluence.plugin.descriptor.JobModuleDescriptor$DelegatingPluginJob.lambda$execute$0(JobModuleDescriptor.java:113) 
at com.atlassian.confluence.impl.vcache.VCacheRequestContextManager.doInRequestContextInternal(VCacheRequestContextManager.java:87) 
at com.atlassian.confluence.impl.vcache.VCacheRequestContextManager.doInRequestContext(VCacheRequestContextManager.java:71) 
at com.atlassian.confluence.plugin.descriptor.JobModuleDescriptor$DelegatingPluginJob.execute(JobModuleDescriptor.java:112) 
at org.quartz.core.JobRunShell.run(JobRunShell.java:223) 
at com.atlassian.confluence.schedule.quartz.ConfluenceQuartzThreadPool.lambda$runInThread$0(ConfluenceQuartzThreadPool.java:16) 
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549) 

는 스택 추적에 따르면, 내가 ' 페이지 저장 중 문제가 발생했습니다 (saveContentEntity). 그것은, 페이지 저장 너무 페이지와 관련된 공간을 업데이 트해야합니다 보인다. 그리고 여기에 문제가 있습니다. 스택 트레이스에 따르면,이 공간은 이미 Hibernate 세션에 존재한다. 실제 세션의 evictclear이 작동하지 않습니다. 제안 사항, 어떻게이 예외를 처리 할 수 ​​있습니까? 아니면 실제로 최대 절전 모드 세션에서 공간을 제거 할 수 있습니까?

감사

+3

당신이 실제로 session.save 전화 코드의 조각을 제공 할 수() session.evict()/session.clear(). 내가 알고 싶었던 한가지 더 많은 정보는 .. (당신이 루프에서 save를 호출했기 때문에) 저장의 첫 번째 시도 동안 예외가 던져 졌는지 또는 던져진 예외 이전에 어떤 객체를 저장할 수 있었는지 여부를 확인할 수 있었습니까? ? – vsoni

+0

엔티티 클래스를 제공하십시오. – MiguelKVidal

답변

0

는 분명히,이 코드에서 무슨 일이 일어나고 있는지입니다 : 내

  1. SpaceManager는 세션이 ID 1과 Session 객체 (즉, 가정)을 찾아 돌려줍니다.
  2. 귀하의 방법은이 참조를 사용하여 다른 객체 인 Page과 연관시킵니다.
  3. 그리고 마지막으로 PageManager은이 데이터를 데이터베이스에 유지합니다.

아마, 문제는 문제가 있음 :
1 단계의 SpaceManager 데이터를 반환 할 때, 거래가 종료하고 반환 된 객체가 detached됩니다 2,에.
그 후 save을 호출하면 분리 된 Session을 유지하려고 시도하지만 데이터베이스에 이미 있습니다. 그런 다음 예외가 발생합니다.

merge 메서드를 사용하거나 엔터티에서이 참조에서 cascade을 제거 할 수 있습니다.

이 (가 아무 잘못이 나있는 당신을 위해 작동하지 않는 경우 그래서 내 대답을 향상시킬 수 있습니다 엔터티 코드를 입력하십시오.)