cancel
Showing results for 
Search instead for 
Did you mean: 

How does Relation Type for 1:n overcomes the problem of Collection Type 1:n

former_member638588
Participant
0 Kudos

Hi

I was going through type system in wiki https://wiki.hybris.com/display/release5/Type+System+Documentation#TypeSystemDocumentation-Relations

What is the exact difference between Relation Type for 1:n and Collection Type 1:n . I have read in wiki that collection should not be used if the they do not scale very well. Second, as a database field only has a limited length, values longer than that length get cut off and are lost.

In simple words how does the Relation type over comes the above problem? What is it internal implementation.

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

amitpanwar
Advisor
Advisor
0 Kudos

Hi Yashwanth,

There is a very small difference as explained below:

  • The source and target item instances are available to both sides of the relation in java classes.

  • It is just required to create a relation for 1:n relation, however for a collection you would need to first create a collection type and then create an attribute of that type in the respective item type.

  • The collection is reusable across multiple item types however the relation isn't.

1:n relation and collection attributes store the data in the respective source item in comma separated pks of the target, hence there is no difference.

However, if you defined an m:1 relation that makes the difference, in that case the target item's pk will be stored in the source item.

For example, if there is a 1:n relation defined as:

 <relation code="FirsttoSecondRel" localized="false">
   <sourceElement qualifier="firstQualifier" type="FirstItem" cardinality="one"/>
   <targetElement qualifier="secondQualifiers" type="SecondItem" cardinality="many"/>
 </relation>

then we recommend to redefine it as an m:1 relation like:

 <relation code="SecondtoFirstRel" localized="false">
       <sourceElement qualifier="secondQualifiers" type="SecondItem" cardinality="many"/>
      <targetElement qualifier="firstQualifier" type="FirstItem" cardinality="one"/>
     </relation>



Answers (0)