Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
Nico Schreiber
Service Builder increment id
22. Februar 2012 23:58
Antwort

Nico Schreiber

Rang: New Member

Nachrichten: 17

Eintrittsdatum: 28. November 2011

Neue 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
David H Nebinger
RE: Service Builder increment id
23. Februar 2012 05:32
Antwort

David H Nebinger

Rang: Liferay Legend

Nachrichten: 7153

Eintrittsdatum: 1. September 2006

Neue 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...
Hitoshi Ozawa
RE: Service Builder increment id
14. April 2012 23:33
Antwort

Hitoshi Ozawa

Rang: Liferay Legend

Nachrichten: 7990

Eintrittsdatum: 23. März 2010

Neue 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
Aliabbas Surti
RE: Service Builder increment id
16. Juli 2013 23:11
Antwort

Aliabbas Surti

Rang: New Member

Nachrichten: 7

Eintrittsdatum: 7. Mai 2013

Neue 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.