Vue combinée Vue Plate Arborescence
Sujets [ Précédent | Suivant ]
toggle
Nico Schreiber
Service Builder increment id
22 février 2012 23:58
Réponse

Nico Schreiber

Rang: New Member

Publications: 17

Date d'inscription: 28 novembre 2011

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
David H Nebinger
RE: Service Builder increment id
23 février 2012 05:32
Réponse

David H Nebinger

Community Moderator

Rang: Liferay Legend

Publications: 11483

Date d'inscription: 1 septembre 2006

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...
Hitoshi Ozawa
RE: Service Builder increment id
14 avril 2012 23:33
Réponse

Hitoshi Ozawa

Rang: Liferay Legend

Publications: 7949

Date d'inscription: 23 mars 2010

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
Aliabbas Surti
RE: Service Builder increment id
16 juillet 2013 23:11
Réponse

Aliabbas Surti

Rang: New Member

Publications: 11

Date d'inscription: 7 mai 2013

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.