Imagine situation when you have already defined model with predefined db index. Like PriceRowModel:

<itemtype code="PriceRow" autocreate="true" generate="true">
   (...)
   <indexes>
      <index name="unique_listprice" unique="true">
         <key attribute="field1"/>
         <key attribute="field2"/>
      </index>
   </indexes>
</itemtype>

Your system is already on production and you have a lot of values inside this table. Then you need to extend the model and create new table, but with different index.

<itemtype code="NewPriceRow" autocreate="true" generate="true">
   (...)
   <indexes>
      <index name="unique_listprice" unique="true">
         <key attribute="field1"/>
         <key attribute="field3"/>
      </index>
   </indexes>
</itemtype>

Like you can see I’ve tried to redefine index unique_listprice. But the result was that old index was created in old version, and the new one was not created at all.

To workaround this situation we need to move unique_listprice to upper abstract class and set autocreate and generate flag to false. Our new working xml will look like this:

<itemtype code="PriceRow" autocreate="false" generate="false">
   (...)
   <!-- indexes element removed -->
</itemtype>
 
<itemtype code="CustomPriceRow" extends="PriceRow" autocreate="true" generate="true">
   (...)
   <indexes>
      <index name="unique_listprice" unique="true">
         <key attribute="field1"/>
         <key attribute="field2"/>
      </index>
   </indexes>
</itemtype>
 
<itemtype code="NewPriceRow" extends="PriceRow" autocreate="true" generate="true">
    (...)
    <indexes>
        <index name="unique_listprice" unique="true">
            <key attribute="field1"/>
            <key attribute="field3"/>
        </index>
    </indexes>
</itemtype>

You can see discussion around this topic in hybris experts community.

Yesterday I faced one problem, how to insert new row to SQLite database with newline char.

First I’ve try to use CHAR(13) function (witch is ASCI newline char), but the Android version of SQLite does not have char function (Exception).

Finally I found the way how to do it:

insert into TABLE ('column') values ('First line, ' || x'0A' || 'Second line.');

Special characters || are responsible for concatenation, tells that his is a HEX value, and 0A is hex representation of Line Feed.

Simple!