Foren

Service Builder increment id

Nico Schreiber, geändert vor 12 Jahren.

Service Builder increment id

New Member Beiträge: 16 Beitrittsdatum: 28.11.11 Neueste Beiträge
Hi,

I have a problem with incrementing my primary key. When I run the service builder, start my server for the first time and add some claims for my database everything works fine. My primary key is incremented. (1,2,3,4, ...) When I shutdown the server, restart them and add another claim it doesn`t work, e.g. the last claimId is 6 and a new claim is saved the claimId increments from 101, 102, .... . Everytime when I restart the server it increments wrong. (first start: 1,2,3 ; second start: 101,102,103 ; third start: 201,202, 203) and so on)

Claim claim = claimPersistence.create(counterLocalService.increment(Claim.class.toString()));

Please help me.

Regards,
Nico
thumbnail
David H Nebinger, geändert vor 12 Jahren.

RE: Service Builder increment id

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
It is not a problem, it's how the counter service is working. It grabs a chunk of 100 ids by default and hands those out during runtime. At server restart it grabs another 100 and hands those out resulting in gaps.

Grabbing 100 at a time is a performance tweak (to only call the db once rather than on each individual id assignment).

I don't remember the property setting to control this, but if you search the forum you'll find a previous thread that talks all about it...
thumbnail
Hitoshi Ozawa, geändert vor 11 Jahren.

RE: Service Builder increment id

Liferay Legend Beiträge: 7942 Beitrittsdatum: 24.03.10 Neueste Beiträge
As David replied, Liferay retrieves a range of index value from the database to increase performance.
When Liferay is restarted, next range is retrieve instead of continuing with the last used value because
Liferay may be clustered and the value of the last used value may already have been used by the
other clustered server. Always getting the next range guarantees avoidance of duplicate values.

#
# Set the number of increments between database updates to the Counter
# table. Set this value to a higher number for better performance.
#
counter.increment=100
thumbnail
Aliabbas Surti, geändert vor 10 Jahren.

RE: Service Builder increment id

New Member Beiträge: 11 Beitrittsdatum: 07.05.13 Neueste Beiträge
Add the following setting into the portal-ext.properties if you want the ids to increment by 1 even if the server is restarted.

counter.increment.<ClassPackage>.<ClassName>=1

For e.g. if the package of your class Claim is com.insurance.entity then the entry would look like,

counter.increment.com.insurance.entity.Claim=1

Hope this helps.