Skip to Content
0
Nov 01, 2016 at 05:31 PM

InterceptorException during new itemmodel save: unique keys {pk=null}

317 Views

I am upgrading an existing hybris 5 application to hybris 6.2.0. During the upgrade I encountered an issue with the UniqueCatalogItemInterceptor. Due to this interceptor i'm unable to save a new item. The application gives me the following exception: de.hybris.platform.servicelayer.interceptor.InterceptorException: [de.hybris.platform.product.impl.UniqueCatalogItemInterceptor@7230d1e8]:unique keys {pk=null} of SizeLineModel () are ambiguous in version Default/Staged

In order to create a better test environment I created a clean hybris 6.2 installation and added my test types. This gives the same exception.

Can anyone help me? Am I doing something wrong?

Items.xml:

 <?xml version="1.0" encoding="ISO-8859-1"?>
 <!--
   ~ [y] hybris Platform
   ~ 
   ~ Copyright (c) 2000-2016 SAP SE
   ~ All rights reserved.
   ~ 
   ~ This software is the confidential and proprietary information of SAP 
   ~ Hybris ("Confidential Information"). You shall not disclose such 
   ~ Confidential Information and shall use it only in accordance with the 
   ~ terms of the license agreement you entered into with SAP Hybris.
   -->
 <!--
     ATTENTION: This is just an example file. You have to edit it according to your needs.
 -->

 <items     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:noNamespaceSchemaLocation="items.xsd">

 <relations>
     <relation code="EANUnitLines" localized="false" generate="true" autocreate="true">
         <sourceElement type="EAN" qualifier="ean" cardinality="one">
             <description>The Parent EAN</description>
             <modifiers read="true" write="true" search="true" optional="true" />
         </sourceElement>
         <targetElement type="UnitLine" qualifier="content" cardinality="many" collectiontype="set">
             <description></description>
             <modifiers read="true" write="true" search="false" partof="true" />
         </targetElement>
     </relation>
 </relations>    


 <itemtypes>
     <itemtype code="UnitLine" jaloclass="org.myproject.jalo.UnitLine" autocreate="true" generate="true">
         <deployment typecode="10506" table="test_unit_line" />
         <custom-properties>
             <!-- marking the type as synchronizing capable here: -->
             <property name="catalogItemType">
                 <value>java.lang.Boolean.TRUE</value>
             </property>
             <property name="catalogVersionAttributeQualifier">
                 <value>"catalogVersion"</value>
             </property>
             <!-- define unique key attributes here; separate multiple attribute qualifiers by commas: -->
             <property name="uniqueKeyAttributeQualifier">
                 <value>"pk"</value>
             </property>
         </custom-properties>
         <attributes>
             <attribute qualifier="catalogVersion" type="CatalogVersion">
                 <modifiers read="true" write="true" search="true" optional="false" />
                 <persistence type="property" />
             </attribute>
             <attribute qualifier="amount" type="java.lang.Double">
                 <modifiers read="true" write="true" search="true" optional="false" />
                 <persistence type="property" />
             </attribute>
             <attribute qualifier="unit" type="Unit">
                 <modifiers read="true" write="true" search="true" optional="true" />
                 <persistence type="property" />
             </attribute>
         </attributes>
     </itemtype>

     <itemtype code="SizeLine" jaloclass="org.myproject.jalo.SizeLine" autocreate="true" generate="true">
         <deployment typecode="10504" table="test_size_line" />
         <custom-properties>
             <!-- marking the type as synchronizing capable here: -->
             <property name="catalogItemType">
                 <value>java.lang.Boolean.TRUE</value>
             </property>
             <property name="catalogVersionAttributeQualifier">
                 <value>"catalogVersion"</value>
             </property>
             <!-- define unique key attributes here; separate multiple attribute qualifiers by commas: -->
             <property name="uniqueKeyAttributeQualifier">
                 <value>"pk"</value>
             </property>
         </custom-properties>
         <attributes>
             <attribute qualifier="catalogVersion" type="CatalogVersion">
                 <modifiers read="true" write="true" search="true" optional="false" />
                 <persistence type="property" />
             </attribute>
             <attribute qualifier="width" type="java.lang.Integer">
                 <modifiers read="true" write="true" search="true" optional="true" />
                 <persistence type="property" />
             </attribute>
             <attribute qualifier="height" type="java.lang.Integer">
                 <modifiers read="true" write="true" search="true" optional="true" />
                 <persistence type="property" />
             </attribute>
             <attribute qualifier="depth" type="java.lang.Integer">
                 <modifiers read="true" write="true" search="true" optional="true" />
                 <persistence type="property" />
             </attribute>
             <attribute qualifier="weight" type="java.lang.Integer">
                 <modifiers read="true" write="true" search="true" optional="true" />
                 <persistence type="property" />
             </attribute>
         </attributes>
     </itemtype>


     <itemtype code="EAN" jaloclass="org.myproject.jalo.EAN" extends="Product" autocreate="true" generate="true">
         <attributes>
             <attribute qualifier="productSize" type="SizeLine">
                 <modifiers read="true" write="true" search="true" optional="true" />
                 <persistence type="property" />
             </attribute>
         </attributes>
     </itemtype>

 </itemtypes>
 </items>


Test code:

 ModelService modelService = Registry.getApplicationContext().getBean("modelService", ModelService.class);

 CatalogVersionModel catalogVersion = modelService.get(PK.fromLong(8796093088345l));
 UnitModel unit = modelService.get(PK.fromLong(8796093054986l));

 UnitLineModel unitLine = modelService.create(UnitLineModel.class);
 unitLine.setCatalogVersion(catalogVersion);
 unitLine.setAmount(1d);
 unitLine.setUnit(unit);

 SizeLineModel sizeLine = modelService.create(SizeLineModel.class);
 sizeLine.setCatalogVersion(catalogVersion);
 sizeLine.setWidth(10);
 sizeLine.setDepth(10);
 sizeLine.setHeight(10);
 sizeLine.setWeight(10);

 EANModel ean = modelService.create(EANModel.class);

 ean.setCode("testean");
 ean.setProductSize(sizeLine);
 ean.setContent(Sets.newHashSet(unitLine));

 modelService.save(ean);

Exception:

de.hybris.platform.servicelayer.interceptor.InterceptorException: [de.hybris.platform.product.impl.UniqueCatalogItemInterceptor@7230d1e8]:unique keys {pk=null} of UnitLineModel () are ambiguous in version Default/Staged at de.hybris.platform.product.impl.UniqueCatalogItemInterceptor.onValidate(UniqueCatalogItemInterceptor.java:95) at de.hybris.platform.servicelayer.internal.model.impl.wrapper.ModelWrapper.invokeValidateInterceptors(ModelWrapper.java:291) at de.hybris.platform.servicelayer.internal.model.impl.wrapper.ModelWrapper.validate(ModelWrapper.java:239) at de.hybris.platform.servicelayer.internal.model.extractor.impl.DefaultModelExtractor.process(DefaultModelExtractor.java:58) at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.performPersistenceOperations(DefaultModelService.java:711) at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.saveAllInternal(DefaultModelService.java:706) at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.saveAll(DefaultModelService.java:686) at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.save(DefaultModelService.java:634) at org.apache.jsp.test_jsp._jspService(test_jsp.java:106) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:254) at de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$StatisticsGatewayFilter.doFilter(AbstractPlatformFilterChain.java:343) at de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:224) at de.hybris.platform.servicelayer.web.WebAppMediaFilter.doFilter(WebAppMediaFilter.java:133) at de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:224) at de.hybris.platform.servicelayer.web.SessionFilter.doFilter(SessionFilter.java:71) at de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:224) at de.hybris.platform.servicelayer.web.Log4JFilter.doFilter(Log4JFilter.java:45) at de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain$InternalFilterChain.doFilter(AbstractPlatformFilterChain.java:224) at de.hybris.platform.servicelayer.web.AbstractPlatformFilterChain.doFilterInternal(AbstractPlatformFilterChain.java:154) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at de.hybris.platform.servicelayer.web.XSSFilter.processPatternsAndDoFilter(XSSFilter.java:293) at de.hybris.platform.servicelayer.web.XSSFilter.doFilter(XSSFilter.java:247) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)