2

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.

Varun Arya
  • 335
  • 1
  • 14

1 Answers1

5

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.

Parth Ghiya
  • 6,929
  • 2
  • 30
  • 37
  • Thanks @Parth, If both has cons. Which is better option then? – Varun Arya Jul 14 '17 at 06:12
  • @VarunArya depends on ur situation sir !! if u dont have clustered env go for Option 1, otherwise i wouldnt want to change to 1.. i see no issues if primary keys are 101,201,301 – Parth Ghiya Jul 14 '17 at 06:32
  • 1
    Agreeing with the comment: choose option 3: an id is just an id. Do not assume anything else than identification. Carry on, there are more important problems to solve – Olaf Kock Jul 14 '17 at 13:59
  • Thanks @ParthGhiya, It was really helpful. :) – Varun Arya Jul 17 '17 at 09:40