The difference between relationships and collections in hybrids?

I'm new to hybris, What are the diff and bfw relationships, why do we go for relationships instead of collections.

+5
source share
8 answers

Basically, there are two technically different ways to model collections in hybrids:

  • CollectionTypes

    • Think of CollectionTypes in hybrids as a backpack set to type
    • Through runtime, CollectionTypes are resolved as a collection of item type, such as MediaModels List
    • It can lead to overflow, which will lead to truncation and, consequently, to data loss.
    • Search difficulty and performance degradation
    • At the database level, CollectionTypes are a comma-separated list of PKs, so there is a maximum
  • Relationtypes

    • Creating relationships between types of types Creating secure n-to-m relationships: only bind such elements of the source / target type declared in relation
    • Relationship values โ€‹โ€‹are stored in a separate database table + Each value is stored in a separate row in the table.
+8
source

I totally agree with @KilleKat's comment, he mentioned all the differences between CollectionType and RelationType in Hybris.

I added some diagrams to have a clearer picture of the subject.

CollectionTypes: (for reasonable use) enter image description here

RelationTypes: (recommended) enter image description here

+7
source

It is important to understand that hybrids severely impede the use of collections; instead, they use relationships.

As indicated above, collections are stored as commas, separated from the data structure, and therefore you can see the problem of data trimming when the relations have a rational data structure to create a new table and a map table to join two tables.

Collection due to storage structure - cannot be found.

I would say that for a very simple (1: n) connection with limited data, you can still use collections. Although for any complex (m: n / 1: n) relationships always use relationships

+1
source

As Sumit said,

CollectionType is not recommended, and RelationType should be used whenever possible. This is because the maximum field length of the CollectionType database is limited, and a CollectionType with many values โ€‹โ€‹can truncate the values. In addition, CollectionTypes are written in CSV format, not normalized. As a result, hybris recommends using RelationTypes when possible.

  • CollectionType: CollectionTypes are based on the Java Collection class, i.e. The collection is a list of items.
    1: n . Keep references to the corresponding values โ€‹โ€‹through an attribute in the source element, for example, a list of primary keys.
    n: 1 . Store the attribute values โ€‹โ€‹in the appropriate target elements and get the getter method in the source type to get the values.
  • RelationType:
    n: m . Inside, elements on both sides of the relationship are connected to each other through instances of an auxiliary type called LinkItem. LinkItems contain two attributes: SourceItem and TargetItem, which store links to the corresponding element.

For each record within the relationship (in other words, for each link from one element to another), there is an instance of LinkItem in which PK of the corresponding elements are stored. LinkItem instances are handled transparently and automatically by the platform: at the API level, you only need to use the appropriate getter and setter methods.

+1
source

In collections we have a limited size. If we try to insert more data, it will be truncated. Relations we can use n no. data.

Collections are faster than relationships, but in collections we can use only one to many relationships, for many, many we should use only relationships.

0
source

Adding to what Raghav added, the collection is internally stored as csv PK in one column. Therefore, the size limit is due to the limitation of the field length in any database.

However, the relationship can be stored in a separate table, and therefore, unlimited matching can be done.

0
source

Collection The root interface in the collection hierarchy.

A collection is a group of objects known as its elements.

Some collections allow you to duplicate elements, while others do not.

Some of them are ordered and others are not ordered.

To get a really good idea of โ€‹โ€‹what is appropriate for each collection and their performance characteristics, I would recommend getting an idea of โ€‹โ€‹data structures such as arrays, linked lists, binary search trees, hash tables, as well as stacks and queues. In fact, there is no way to learn this if you want to be an effective programmer in any language.

HashMap is used only for cases when there is a logical reason to have special keys corresponding to the values

0
source

Collections are saved as a serialized object in one column in the database.

Relations are stored in the usual way of a relational database - using a foreign key in another table or link table (depending on the strength of the relationship)

Collection types are discouraged because they cannot be found using flexiblesearch and have significant performance limitations when working with collections of more than a few objects.

0
source

Source: https://habr.com/ru/post/1212256/


All Articles