2017-11-22 16 views
2

は、ページの作成に関して、Conluenceのquartz Jobに大きな問題がありました。スケジュールされたジョブで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は機能しません。 どのような提案、どのようにこの例外を処理することができますか、または実際にはHibernateセッションからスペースを削除するにはどうすればいいですか?

おかげで

+3

、あなたが実際に(session.saveを呼び出すコードの一部を提供することができます)、 session.evict()/ session.clear()を呼び出します。私が知りたいと思ったもう1つの情報は、(あなたがループ内でsaveを呼び出しているので)最初の保存時に例外がスローされたかどうか、または例外がスローされる前にいくつかのオブジェクトを保存できたかどうか? – vsoni

+0

エンティティクラスを提供してください。 – MiguelKVidal

答えて

0

どうやら、これはあなたのコード内で何が起こっているかである:あなたのSpaceManager以内

  1. 、あなたのセッションは、ID 1でSessionオブジェクトを検索します(のように仮定し)、それを返します。
  2. このメソッドは、この参照を使用して別のオブジェクト(Page)と関連付けます。
  3. 最後に、PageManagerはこのデータをデータベースに保存します。 、2のステップ1から
    SpaceManagerがデータを返すとき、あなたのトランザクションが終了すると、あなたの返されるオブジェクトはdetached次のようになります。

はおそらく、あなたの問題は、という問題です。
その後、saveを呼び出すと、デタッチされたSessionを永続化しようとしていますが、すでにデータベースに存在しています。その後、例外が発生します。

mergeメソッドを使用するか、エンティティ内のこの参照からcascadeを削除することができます。

(エンティティ・コードがあなたのために動作しない何かかがあるかどうので、私は私の答えを向上させることができます提供してください。)

関連する問題