掲示板

Service Builder increment id

12年前 に Nico Schreiber によって更新されました。

Service Builder increment id

New Member 投稿: 16 参加年月日: 11/11/28 最新の投稿
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
12年前 に David H Nebinger によって更新されました。

RE: Service Builder increment id

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
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
12年前 に Hitoshi Ozawa によって更新されました。

RE: Service Builder increment id

Liferay Legend 投稿: 7942 参加年月日: 10/03/24 最新の投稿
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
10年前 に Aliabbas Surti によって更新されました。

RE: Service Builder increment id

New Member 投稿: 11 参加年月日: 13/05/07 最新の投稿
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.