<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: DataIntegrityViolation exception in Integration Test in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/dataintegrityviolation-exception-in-integration-test/m-p/137748#M36954</link>
    <description>&lt;P&gt;Without knowing what you are doing precisely in your extended SiteService, and also what kind of operations are done in the test before that point, it is impossible to say what is causing the data integrity violation. Usually this is a sign of some operation not properly updating / removing a cache entry after a modification has taken place&lt;/P&gt;</description>
    <pubDate>Fri, 18 Jun 2021 09:37:16 GMT</pubDate>
    <dc:creator>afaust</dc:creator>
    <dc:date>2021-06-18T09:37:16Z</dc:date>
    <item>
      <title>DataIntegrityViolation exception in Integration Test</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/dataintegrityviolation-exception-in-integration-test/m-p/137747#M36953</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;we are developing an extension of alfresco to manage custom models.&amp;nbsp; Version 7.0.0, SDK 4.2.&lt;/P&gt;&lt;P&gt;We needed an extesion of Site to store extra properties, so we define our custom type Project.&lt;/P&gt;&lt;P&gt;Then, we extend the &lt;STRONG&gt;SiteServiceImpl&lt;/STRONG&gt; to inherit all &lt;EM&gt;Site&lt;/EM&gt; business logic and configure the bean in service-context.xml.&lt;/P&gt;&lt;P&gt;Sometimes, the integration tests fails with this message:&lt;/P&gt;&lt;PRE&gt;org.springframework.dao.DataIntegrityViolationException: Detected stale node entry: NodeVersionKey [nodeId=32, version=12] (now NodeVersionKey [nodeId=32, version=13])&lt;/PRE&gt;&lt;P&gt;This is the complete stacktrace (I cut some lines due to the message limit)&lt;/P&gt;&lt;PRE&gt;org.springframework.dao.DataIntegrityViolationException: Detected stale node entry: NodeVersionKey [nodeId=32, version=12] (now NodeVersionKey [nodeId=32, version=13])&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.domain.node.AbstractNodeDAOImpl.loadParentAssocs(AbstractNodeDAOImpl.java:4418)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.domain.node.AbstractNodeDAOImpl.getParentAssocsCached(AbstractNodeDAOImpl.java:4311)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.domain.node.AbstractNodeDAOImpl.newChildAssoc(AbstractNodeDAOImpl.java:3194)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.node.db.DbNodeServiceImpl.addChild_aroundBody46(DbNodeServiceImpl.java:1320)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.node.db.DbNodeServiceImpl$AjcClosure47.run(DbNodeServiceImpl.java:1)&lt;BR /&gt;[33medi-acs_1 |[0m at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:167)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.traitextender.RouteExtensions.intercept(RouteExtensions.java:100)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.node.db.DbNodeServiceImpl.addChild(DbNodeServiceImpl.java:1293)&lt;BR /&gt;[33medi-acs_1 |[0m at jdk.internal.reflect.GeneratedMethodAccessor450.invoke(Unknown Source)&lt;BR /&gt;[33medi-acs_1 |[0m at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)&lt;BR /&gt;[33medi-acs_1 |[0m at java.base/java.lang.reflect.Method.invoke(Method.java:566)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.lock.mem.LockableAspectInterceptor.invoke(LockableAspectInterceptor.java:244)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)&lt;BR /&gt;[33medi-acs_1 |[0m at com.sun.proxy.$Proxy32.addChild(Unknown Source)&lt;BR /&gt;[33medi-acs_1 |[0m at jdk.internal.reflect.GeneratedMethodAccessor450.invoke(Unknown Source)&lt;BR /&gt;[33medi-acs_1 |[0m at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)&lt;BR /&gt;[33medi-acs_1 |[0m at java.base/java.lang.reflect.Method.invoke(Method.java:566)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.tenant.MultiTNodeServiceInterceptor.invoke(MultiTNodeServiceInterceptor.java:111)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)&lt;BR /&gt;[33medi-acs_1 |[0m at com.sun.proxy.$Proxy32.addChild(Unknown Source)&lt;BR /&gt;[33medi-acs_1 |[0m at jdk.internal.reflect.GeneratedMethodAccessor450.invoke(Unknown Source)&lt;BR /&gt;[33medi-acs_1 |[0m at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)&lt;BR /&gt;[33medi-acs_1 |[0m at java.base/java.lang.reflect.Method.invoke(Method.java:566)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.service.StoreRedirectorProxyFactory$RedirectorInvocationHandler.invoke(StoreRedirectorProxyFactory.java:231)&lt;BR /&gt;[33medi-acs_1 |[0m at com.sun.proxy.$Proxy48.addChild(Unknown Source)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.security.authority.AuthorityDAOImpl.addAuthority(AuthorityDAOImpl.java:369)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.security.authority.AuthorityServiceImpl.addAuthority(AuthorityServiceImpl.java:485)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.security.authority.AuthorityServiceImpl.addAuthority(AuthorityServiceImpl.java:477)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.site.SiteServiceImpl$3.doWork(SiteServiceImpl.java:722)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.site.SiteServiceImpl$3.doWork(SiteServiceImpl.java:1)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:602)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.site.SiteServiceImpl.setupSitePermissions(SiteServiceImpl.java:626)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.site.SiteServiceImpl.setupSitePermissions(SiteServiceImpl.java:616)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.site.SiteServiceImpl.createSite(SiteServiceImpl.java:584)&lt;BR /&gt;[33medi-acs_1 |[0m at com.stamtech.edi.services.ProjectServiceImpl.createProject(ProjectServiceImpl.java:234)&lt;BR /&gt;[33medi-acs_1 |[0m at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)&lt;BR /&gt;[33medi-acs_1 |[0m at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)&lt;BR /&gt;[33medi-acs_1 |[0m at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)&lt;BR /&gt;[33medi-acs_1 |[0m at java.base/java.lang.reflect.Method.invoke(Method.java:566)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)&lt;BR /&gt;[33medi-acs_1 |[0m at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:80)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:53)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:166)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.transaction.CheckTransactionAdvice.invoke(CheckTransactionAdvice.java:54)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.transaction.RetryingTransactionAdvice$1.execute(RetryingTransactionAdvice.java:71)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:450)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.transaction.RetryingTransactionAdvice.invoke(RetryingTransactionAdvice.java:74)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)&lt;BR /&gt;[33medi-acs_1 |[0m at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)&lt;BR /&gt;[33medi-acs_1 |[0m at com.sun.proxy.$Proxy169.createProject(Unknown Source)&lt;BR /&gt;[33medi-acs_1 |[0m at com.stamtech.edi.test.utils.MockProject$1.execute(MockProject.java:43)&lt;BR /&gt;[33medi-acs_1 |[0m at com.stamtech.edi.test.utils.MockProject$1.execute(MockProject.java:41)&lt;BR /&gt;[33medi-acs_1 |[0m at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:450)&lt;BR /&gt;[33medi-acs_1 |[0m at com.stamtech.edi.test.utils.MockProject.createProject(MockProject.java:49)&lt;BR /&gt;[33medi-acs_1 |[0m at com.stamtech.edi.test.behaviors.ProjectBehaviorIT.whenCreateProjectThenCheckFolders(ProjectBehaviorIT.java:34)&lt;BR /&gt;...&lt;/PRE&gt;&lt;P&gt;In our tests we create Project using the&amp;nbsp;RetryingTransactionCallback, but the exception is thrown even if we don't use this class.&lt;/P&gt;&lt;PRE&gt;RetryingTransactionCallback&amp;lt;NodeRef&amp;gt; callback = new RetryingTransactionCallback&amp;lt;NodeRef&amp;gt;() {
            public NodeRef execute() throws Throwable {
                ProjectResource createdProjectResource = projectService.createProject(projectResource);
                return createdProjectResource.getNodeRef();
            }
        };
        try {
            RetryingTransactionHelper transactionHelper = transactionService.getRetryingTransactionHelper();
            NodeRef projectRef = transactionHelper.doInTransaction(callback);
            return projectRef;
        } catch (Throwable e) {
            e.printStackTrace();
            throw e;
        }&lt;/PRE&gt;&lt;P&gt;what goes wrong?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sevastian&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jun 2021 07:19:43 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/dataintegrityviolation-exception-in-integration-test/m-p/137747#M36953</guid>
      <dc:creator>ilseva</dc:creator>
      <dc:date>2021-06-18T07:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: DataIntegrityViolation exception in Integration Test</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/dataintegrityviolation-exception-in-integration-test/m-p/137748#M36954</link>
      <description>&lt;P&gt;Without knowing what you are doing precisely in your extended SiteService, and also what kind of operations are done in the test before that point, it is impossible to say what is causing the data integrity violation. Usually this is a sign of some operation not properly updating / removing a cache entry after a modification has taken place&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jun 2021 09:37:16 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/dataintegrityviolation-exception-in-integration-test/m-p/137748#M36954</guid>
      <dc:creator>afaust</dc:creator>
      <dc:date>2021-06-18T09:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: DataIntegrityViolation exception in Integration Test</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/dataintegrityviolation-exception-in-integration-test/m-p/137749#M36955</link>
      <description>&lt;P&gt;Hi, thanks for you reply.&lt;/P&gt;&lt;P&gt;This is the test method&lt;/P&gt;&lt;PRE&gt;@RunWith(value = AlfrescoTestRunner.class)&lt;BR /&gt;public class ProjectBehaviorIT extends AbstractAlfrescoIT {&lt;BR /&gt;@Test
    public void whenCreateProjectThenCheckFolders() {
        NodeRef projectNodeRef = MockProject.createProject(getApplicationContext(), "TEST", false);
        Assert.assertNotNull(projectNodeRef);&lt;BR /&gt;        ...
    }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;This is the MockProject utils method&lt;/P&gt;&lt;PRE&gt;public static NodeRef createProject(ApplicationContext context, String projectName, boolean newTransaction) {
        TransactionService transactionService = (TransactionService) context.getBean("transactionService");
        ProjectService projectService = (ProjectService) context.getBean("projectService");
        String adminUserName = AuthenticationUtil.getAdminUserName();
        AuthenticationUtil.setFullyAuthenticatedUser(adminUserName);
        final ProjectResource projectResource = new ProjectResource();
        projectResource.setProjectName(projectName);
        LocalDate startDate = LocalDate.now();
        projectResource.setProjectStartDate(Date.from(startDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()));
        projectResource.setProjectEndDate(Date.from(startDate.plusYears(1).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()));
        projectResource.setProjectVisibility("private");
        
        RetryingTransactionCallback&amp;lt;NodeRef&amp;gt; callback = new RetryingTransactionCallback&amp;lt;NodeRef&amp;gt;() {
            public NodeRef execute() throws Throwable {
                ProjectResource createdProjectResource = projectService.createProject(projectResource);
                return createdProjectResource.getNodeRef();
            }
        };
        try {
            RetryingTransactionHelper transactionHelper = transactionService.getRetryingTransactionHelper();
            NodeRef projectRef = transactionHelper.doInTransaction(callback, false, newTransaction);
            return projectRef;
        } catch (Throwable e) {
            e.printStackTrace();
            throw e;
        }
    }&lt;/PRE&gt;&lt;P&gt;Finally this is the ProjectServiceImpl that extends SiteServiceImpl&lt;/P&gt;&lt;PRE&gt;public class ProjectServiceImpl extends SiteServiceImpl implements ProjectService {
....
 @Override
    public ProjectResource createProject(ProjectResource project) {
        QName nodeType = QName.createQName(EdiModel.EDI_MODEL_URI, EdiModel.TYPE_EDI_PROJECT);
            
            SiteInfo ediSite = createSite(EdiModel.TYPE_EDI_PROJECT
                , project.getProjectName()
                , project.getProjectName()
                , project.getProjectDescription()
                , setProjectVisibility(project.getProjectVisibility())
                , nodeType);

            project.setProjectStatus(ProjectStatus.RELEASE_0.getLabel());

            try {
                Map&amp;lt;QName, Serializable&amp;gt; defaultSiteProperties = nodeService.getProperties(ediSite.getNodeRef());
                defaultSiteProperties.putAll(setProjectProperties(project));
                nodeService.setProperties(ediSite.getNodeRef(), defaultSiteProperties);
                
                /** we clear the inherited permissions from the project, which is the node parent, and set up 
                 * specific local permissions for the folder BuildingSite
                 * 
                 * REMARK: IF WE CHANGE THE BEHAVIOUR POLICY FOR THE EVENT "onCreateNode" ( ProjectBehaviour.java) CHECK OUT THE FOLDER BUILDINGSITE 
                 * IS AVAILABLE AND THE LOCAL PERMISSIONS ARE SET UP CORRECTLY */
                NodeRef buildingSiteFolder = nodeService.getChildByName(ediSite.getNodeRef(), ContentModel.ASSOC_CONTAINS, EdiModel.FOLDER_BUILDING_SITE_DOCS);
                permissionService.setInheritParentPermissions(buildingSiteFolder, false);
                setLocalPermissionsOnFolder(buildingSiteFolder, ediSite.getNodeRef());
                
                project.setNodeRef(ediSite.getNodeRef());
                project.setId(ediSite.getShortName());

                return project;
            } catch (InvalidNodeRefException ex) {
                throw new SiteServiceException("Impossible to create the project");
            }
    }&lt;/PRE&gt;&lt;P&gt;We have a behavior defined for onCreateNode event thats create default folders inside Project.&lt;/P&gt;&lt;P&gt;Thanks for support.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jun 2021 14:56:23 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/dataintegrityviolation-exception-in-integration-test/m-p/137749#M36955</guid>
      <dc:creator>ilseva</dc:creator>
      <dc:date>2021-06-18T14:56:23Z</dc:date>
    </item>
    <item>
      <title>Re: DataIntegrityViolation exception in Integration Test</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/dataintegrityviolation-exception-in-integration-test/m-p/137750#M36956</link>
      <description>&lt;P&gt;Did you find a workaround ?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2024 15:14:23 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/dataintegrityviolation-exception-in-integration-test/m-p/137750#M36956</guid>
      <dc:creator>AlfrescoZZZ</dc:creator>
      <dc:date>2024-02-07T15:14:23Z</dc:date>
    </item>
  </channel>
</rss>

