liferayliferay-service-builder

Liferay Service Builder Table Auto Increment On Each Deployment


In liferay i have a entity as below:

<entity name="Foo" local-service="true" remote-service="true">

        <!-- PK fields -->

        <column name="fooId" type="long" primary="true" />

        <!-- Group instance -->

        <column name="groupId" type="long" />

        <!-- Audit fields -->

        <column name="companyId" type="long" />
        <column name="userId" type="long" />
        <column name="userName" type="String" />
        <column name="createDate" type="Date" />
        <column name="modifiedDate" type="Date" />

        <!-- Other fields -->

        <column name="field1" type="String" />
        <column name="field2" type="boolean" />
        <column name="field3" type="int" />
        <column name="field4" type="Date" />
        <column name="field5" type="String" />

        <!-- Order -->

        <order by="asc">
            <order-column name="field1" />
        </order>

        <!-- Finder methods -->

        <finder name="Field2" return-type="Collection">
            <finder-column name="field2" />
        </finder>
    </entity>

When i change the code of the portlet. On each deployment its primary key increases by 100. So there is anyway to set it auto increment by 1 only. And it must not be incremented by 100 on each deploy.


Solution

  • Option#1

    Add this in your primary key column id-type="increment"

    i.e

    <column name="fooId" type="long" primary="true" id-type="increment" />
    

    Cons: This WILL BREAK IN CLUSTERED Environment

    Option#2

    add this in portal-ext.properties

    #
    # Set the number of increments between database updates to the Counter
    # table. Set this value to a higher number for better performance.
    #
    counter.increment=1 //by default it is 100
    

    Cons: this will impact your performance.