掲示板

CounterLocalServiceUtil.increment() not working proplerly

11年前 に Samita Bhujbal によって更新されました。

CounterLocalServiceUtil.increment() not working proplerly

Regular Member 投稿: 117 参加年月日: 11/07/05 最新の投稿
Hi I am using liferay 6.0.6. I am working with service builder where i generate entities and store data in them.
While setting primary Id for entity i use CounterLocalServiceUtil.increment(MemberContactDetails.class.getName()) method where "MemberContactDetails" is my entity name . but sometimes this method generates same PrimaryId again that's why I get exception and data doesn't get saved in table.


Does anyone knows reason behind this???
11年前 に Siby Mathew によって更新されました。

RE: CounterLocalServiceUtil.increment() not working proplerly

Expert 投稿: 268 参加年月日: 11/03/04 最新の投稿
Hi Samita,
Are you using like :

obj = *LocalServiceUtil.create(CounterLocalServiceUtil.increment(MemberContactDetails.class.getName()));
//set the values to obj
*LocalServiceUtil.update(obj);



Thanks,
Siby
11年前 に Samita Bhujbal によって更新されました。

RE: CounterLocalServiceUtil.increment() not working proplerly

Regular Member 投稿: 117 参加年月日: 11/07/05 最新の投稿
No.
Following is my code :-
long MemberContactDetailID = CounterLocalServiceUtil.increment(MemberContactDetails.class.getName());
MemberContDetail.setMemberContactDetailID(MemberContactDetailID);


Here "MemberContactDetails" is my entity and "MemberContactDetailID" is primary id.
thumbnail
11年前 に Jitendra Rajput によって更新されました。

RE: CounterLocalServiceUtil.increment() not working proplerly

Liferay Master 投稿: 875 参加年月日: 11/01/07 最新の投稿
#
# 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

try by setting above property to maximum value like 2000 and then verify . Not sure what exactly issue with your case.
11年前 に Siby Mathew によって更新されました。

RE: CounterLocalServiceUtil.increment() not working proplerly

Expert 投稿: 268 参加年月日: 11/03/04 最新の投稿
Hi,
How did you create this object variable : "MemberContDetail" ?
[ Tip: Please start all your variables with smaller case ]

Usually you can create this by :
MemberContactDetails  memberContDetail = MemberContDetailsLocalServiceUtil.create(CounterLocalServiceUtil.increment(MemberContactDetails.class.getName()))


In this case the primary key is already applied.
Check your code if this is the same logic.

Thanks,
Siby
11年前 に Samita Bhujbal によって更新されました。

RE: CounterLocalServiceUtil.increment() not working proplerly

Regular Member 投稿: 117 参加年月日: 11/07/05 最新の投稿
thanks for reply Siby.
I am creating entity by creating service.xml file. Variable is defined in service.xml.
11年前 に Siby Mathew によって更新されました。

RE: CounterLocalServiceUtil.increment() not working proplerly

Expert 投稿: 268 参加年月日: 11/03/04 最新の投稿
Hi Samita,
Yes I understand the entity name is defined in the service.xml.
Please post your full update code so that its easier to analyse.

Thanks,
Siby
11年前 に Samita Bhujbal によって更新されました。

RE: CounterLocalServiceUtil.increment() not working proplerly

Regular Member 投稿: 117 参加年月日: 11/07/05 最新の投稿
Following is my code :

PgDegreeMapping AddPgDegreeMapping = new PgDegreeMappingImpl();

long PgDegreeMappingID = CounterLocalServiceUtil.increment(PgDegreeMapping.class.getName());

AddPgDegreeMapping.setPgDegreeMappingID(PgDegreeMappingID);
AddPgDegreeMapping.setPgDegreeID(PgDegreeID);
AddPgDegreeMapping.setMemberCode(MemberCode);
AddPgDegreeMapping.setInstituteName(PgInstituteName);
AddPgDegreeMapping.setStartYear(PgStartYear);
AddPgDegreeMapping.setEndYear(PgEndYear);
AddPgDegreeMapping.setSpecialisation(PgSpecialization);

PgDegreeMappingLocalServiceUtil.addPgDegreeMapping(AddPgDegreeMapping);
11年前 に Siby Mathew によって更新されました。

RE: CounterLocalServiceUtil.increment() not working proplerly

Expert 投稿: 268 参加年月日: 11/03/04 最新の投稿
Hi Samita,
You are doing it wrong.
You should not instantiate the PgDegreeMappingImpl()
Instead do this :

 PgDegreeMapping addPgDegreeMapping = PgDegreeMappingLocalServiceUtil.create(CounterLocalServiceUtil.increment(PgDegreeMapping.class.getName()));
 //Set all the values
 //Update


Thanks,
Siby
11年前 に Samita Bhujbal によって更新されました。

RE: CounterLocalServiceUtil.increment() not working proplerly

Regular Member 投稿: 117 参加年月日: 11/07/05 最新の投稿
Thanks for reply Siby. emoticon I will try this solution.
thumbnail
11年前 に Prakash Khanchandani によって更新されました。

RE: CounterLocalServiceUtil.increment() not working proplerly

Expert 投稿: 329 参加年月日: 11/02/10 最新の投稿
Also @Samita if possible start your variables with lowerCase.

Following conventions helps a lot in maintaining your code, you can refer to Java Code Conventions for more info, this is a nice and comprehensive code convention document and also explains the need for code-convention convincingly.

Thanks