Foros de discusión

CounterLocalServiceUtil.increment() not working proplerly

Samita Bhujbal, modificado hace 11 años.

CounterLocalServiceUtil.increment() not working proplerly

Regular Member Mensajes: 117 Fecha de incorporación: 5/07/11 Mensajes recientes
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???
Siby Mathew, modificado hace 11 años.

RE: CounterLocalServiceUtil.increment() not working proplerly

Expert Mensajes: 268 Fecha de incorporación: 4/03/11 Mensajes recientes
Hi Samita,
Are you using like :

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



Thanks,
Siby
Samita Bhujbal, modificado hace 11 años.

RE: CounterLocalServiceUtil.increment() not working proplerly

Regular Member Mensajes: 117 Fecha de incorporación: 5/07/11 Mensajes recientes
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
Jitendra Rajput, modificado hace 11 años.

RE: CounterLocalServiceUtil.increment() not working proplerly

Liferay Master Mensajes: 875 Fecha de incorporación: 7/01/11 Mensajes recientes
#
# 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.
Siby Mathew, modificado hace 11 años.

RE: CounterLocalServiceUtil.increment() not working proplerly

Expert Mensajes: 268 Fecha de incorporación: 4/03/11 Mensajes recientes
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
Samita Bhujbal, modificado hace 11 años.

RE: CounterLocalServiceUtil.increment() not working proplerly

Regular Member Mensajes: 117 Fecha de incorporación: 5/07/11 Mensajes recientes
thanks for reply Siby.
I am creating entity by creating service.xml file. Variable is defined in service.xml.
Siby Mathew, modificado hace 11 años.

RE: CounterLocalServiceUtil.increment() not working proplerly

Expert Mensajes: 268 Fecha de incorporación: 4/03/11 Mensajes recientes
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
Samita Bhujbal, modificado hace 11 años.

RE: CounterLocalServiceUtil.increment() not working proplerly

Regular Member Mensajes: 117 Fecha de incorporación: 5/07/11 Mensajes recientes
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);
Siby Mathew, modificado hace 11 años.

RE: CounterLocalServiceUtil.increment() not working proplerly

Expert Mensajes: 268 Fecha de incorporación: 4/03/11 Mensajes recientes
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
Samita Bhujbal, modificado hace 11 años.

RE: CounterLocalServiceUtil.increment() not working proplerly

Regular Member Mensajes: 117 Fecha de incorporación: 5/07/11 Mensajes recientes
Thanks for reply Siby. emoticon I will try this solution.
thumbnail
Prakash Khanchandani, modificado hace 11 años.

RE: CounterLocalServiceUtil.increment() not working proplerly

Expert Mensajes: 329 Fecha de incorporación: 10/02/11 Mensajes recientes
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