cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Import new data for One-to-One entities by Impex import

Former Member
0 Kudos
365

Hi, I have been trying to create a simple relation between two entities "Car" and "Engine". So, due to One-to-One it's not a relation. Here is my items:

    <itemtypes>
         <itemtype code="Car" extends="GenericItem" autocreate="true" generate="true">
             <deployment table="Car" typecode="10111"/>
             <attributes>
                 <attribute qualifier="engine" type="Engine">
                     <persistence type="property"/>
                 </attribute>
             </attributes>
         </itemtype>
         
         <itemtype code="Engine" extends="GenericItem" autocreate="true" generate="true">
             <deployment table="Engine" typecode="10112"/>
             <attributes>
                 <attribute qualifier="power" type="java.lang.Integer">
                     <persistence type="property"/>
                 </attribute>
             </attributes>
         </itemtype>
     </itemtypes>


Here is my wrong impex file.

 INSERT Car; name[unique=true]; &engineid;
           ; Bentley; engineuid
           ; Lada; engineuid
           ; Zaporojec; engineuid
 
 INSERT Engine; name[unique=true]; power; pk[unique = true]
              ; Hemi; 1500; engineuid
              ; Chevrolet; 600; engineuid
              ; Nuclear; 1000000; engineuid

How it should looks like to import new data for created itemtypes above? Thanks in advance!

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Thanx guys, it works!

Former Member
0 Kudos

This code is works for me.

Changes for itemtypes. So, if itemtype extends from GenericType new uid filed should be created.

 <itemtypes>
         <itemtype code="Car" extends="GenericItem" autocreate="true" generate="true">
             <deployment table="Car" typecode="10111"/>
             <attributes>
                 <attribute qualifier="name" type="java.lang.String">
                     <persistence type="property"/>
                     <modifiers read="true" initial="true" write="true" search="true" optional="false"/>
                 </attribute>
                 <attribute qualifier="engine" type="Engine">
                     <persistence type="property"/>
                 </attribute>
                 <attribute qualifier="uid" autocreate="true" type="java.lang.String" generate="true">
                     <persistence type="property"/>
                     <modifiers read="true" initial="true" write="false" search="true" optional="false" unique="true"/>
                 </attribute>
             </attributes>
             <indexes>
                 <index name="UID" unique="true">
                     <key attribute="uid"/>
                 </index>
             </indexes>
         </itemtype>
         
         <itemtype code="Engine" extends="GenericItem" autocreate="true" generate="true">
             <deployment table="Engine" typecode="10112"/>
             <attributes>
                 <attribute qualifier="power" type="java.lang.Integer">
                     <persistence type="property"/>
                 </attribute>
                 <attribute qualifier="uid" autocreate="true" type="java.lang.String" generate="true">
                     <persistence type="property"/>
                     <modifiers read="true" initial="true" write="false" search="true" optional="false" unique="true"/>
                 </attribute>
             </attributes>
             <indexes>
                 <index name="UID" unique="true">
                     <key attribute="uid"/>
                 </index>
             </indexes>
         </itemtype>
     </itemtypes>


Before run script Hybris required update for persistance: Impex script for update:

 INSERT Engine; uid[unique=true]; name; power;
           ; hemi; Hemi; 1500
           ; chevrolet; Chevrolet; 600
           ; nuclear; Nuclear; 1000000
 
 INSERT Car; uid[unique = true]; name; engine(uid)
           ; bentley; Bentley; hemi
           ; lada; Lada; chevrolet
           ; zaporozhetz;Zaporojec; nuclear

Marko_salonen
Contributor
0 Kudos

Hi, you seem to be missing name property that is not unique. And you are trying to set a PK value that you should not do . Instead you should add a UID or ID property that is of type String . Then your import could look something like:

INSERT_UPDATE Engine;UID[unique=true];power ;Hemi;1500 ;Chevorlet;600 ; Nuclear; 1000000 INSERT_UPDATE Car;UID[unique=true];engine(uid[unique=true]) ; Bentley;Hemi ; Lada; Chevrolet ; Zaporojec; Nuclear

You should never set the pk value because hybris takes care of it. But you might use PK values to reference unique items in the impex.