cancel
Showing results for 
Search instead for 
Did you mean: 

When do we use maptype in hybris ? What kind of functionality can be implemented using it ? Can you please explain it with a real time example.

Former Member
0 Kudos
 

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member632755
Active Contributor
0 Kudos

Hi,

as far as I understand the persistence layer design:

  • maptypes are present in the platform and may be used (they are NOT deprecated)
  • when you want to declare a maptype be sure that you have a really good reason for doing so - usually it is becaouse of bad design and there is a better solution

Cheers

Former Member
0 Kudos

Hello,

A MapType is a typed collection of key/value pairs. For each key (referred to as argument), there is a corresponding value (referred to as return type). The direction of mapping is always argument -> return value.

A very common use of MapTypes is localized values - values that may differ in every language available in the system, like product descriptions in German and English, for example.

They are declares in your extension-items.xml file, as the relations or enums, using the tags:

 <maptypes>
     ...
 </maptypes>

One possible declaration would be in the cms extension, to associate URL to Items and Types to Rules

     <maptypes>
         <maptype code="UrlToItem"
                     argumenttype="java.lang.String"
                     returntype="Item"
                     autocreate="true"
                     generate="false"/>                        
         <maptype code="TypeToRule"
                     argumenttype="ComposedType"
                     returntype="java.lang.String"
                     autocreate="true"
                     generate="false"/>                                            
     </maptypes>

However, after 5th version, its use is not recommended and it should be considered deprecated

Best regards,

Former Member
0 Kudos

If it's use is no longer recommend and it is considered deprecated, what is the recommended alternate approach for such situations?

Thanks

former_member632755
Active Contributor
0 Kudos

Hi,

for real-life examples take a look at core-items.xml. For example all localized strings are stored using maptype:

       <maptype code="localized:java.lang.String"
              argumenttype="Language"
              returntype="java.lang.String"
              autocreate="true"
              generate="false"/>

More examples in the file.

Cheers, Wojtek

Former Member
0 Kudos

Thanks Wojtek !