Forums de discussion

Service Builder increment id

Nico Schreiber, modifié il y a 12 années.

Service Builder increment id

New Member Publications: 16 Date d'inscription: 28/11/11 Publications récentes
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, modifié il y a 12 années.

RE: Service Builder increment id

Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
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, modifié il y a 11 années.

RE: Service Builder increment id

Liferay Legend Publications: 7942 Date d'inscription: 24/03/10 Publications récentes
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, modifié il y a 10 années.

RE: Service Builder increment id

New Member Publications: 11 Date d'inscription: 07/05/13 Publications récentes
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.