Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Samita Bhujbal
CounterLocalServiceUtil.increment() not working proplerly
February 4, 2013 1:55 AM
Answer

Samita Bhujbal

Rank: Regular Member

Posts: 120

Join Date: July 5, 2011

Recent Posts

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
RE: CounterLocalServiceUtil.increment() not working proplerly
February 4, 2013 2:33 AM
Answer

Siby Mathew

Rank: Expert

Posts: 259

Join Date: March 4, 2011

Recent Posts

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
RE: CounterLocalServiceUtil.increment() not working proplerly
February 4, 2013 2:52 AM
Answer

Samita Bhujbal

Rank: Regular Member

Posts: 120

Join Date: July 5, 2011

Recent Posts

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.
Jitendra Rajput
RE: CounterLocalServiceUtil.increment() not working proplerly
February 4, 2013 3:23 AM
Answer

Jitendra Rajput

Rank: Liferay Master

Posts: 657

Join Date: January 7, 2011

Recent Posts

#
# 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
RE: CounterLocalServiceUtil.increment() not working proplerly
February 4, 2013 4:45 AM
Answer

Siby Mathew

Rank: Expert

Posts: 259

Join Date: March 4, 2011

Recent Posts

Hi,
How did you create this object variable : "MemberContDetail" ?
[ Tip: Please start all your variables with smaller case ]

Usually you can create this by :
1MemberContactDetails  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
RE: CounterLocalServiceUtil.increment() not working proplerly
February 4, 2013 5:54 AM
Answer

Samita Bhujbal

Rank: Regular Member

Posts: 120

Join Date: July 5, 2011

Recent Posts

thanks for reply Siby.
I am creating entity by creating service.xml file. Variable is defined in service.xml.
Siby Mathew
RE: CounterLocalServiceUtil.increment() not working proplerly
February 4, 2013 6:08 AM
Answer

Siby Mathew

Rank: Expert

Posts: 259

Join Date: March 4, 2011

Recent Posts

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
RE: CounterLocalServiceUtil.increment() not working proplerly
February 4, 2013 11:29 PM
Answer

Samita Bhujbal

Rank: Regular Member

Posts: 120

Join Date: July 5, 2011

Recent Posts

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
RE: CounterLocalServiceUtil.increment() not working proplerly
February 5, 2013 2:25 AM
Answer

Siby Mathew

Rank: Expert

Posts: 259

Join Date: March 4, 2011

Recent Posts

Hi Samita,
You are doing it wrong.
You should not instantiate the PgDegreeMappingImpl()
Instead do this :

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


Thanks,
Siby
Samita Bhujbal
RE: CounterLocalServiceUtil.increment() not working proplerly
February 5, 2013 3:28 AM
Answer

Samita Bhujbal

Rank: Regular Member

Posts: 120

Join Date: July 5, 2011

Recent Posts

Thanks for reply Siby. emoticon I will try this solution.
Prakash Khanchandani
RE: CounterLocalServiceUtil.increment() not working proplerly
February 7, 2013 5:22 AM
Answer

Prakash Khanchandani

Rank: Regular Member

Posts: 235

Join Date: February 10, 2011

Recent Posts

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