Liferay Service Builder Autoincrement With Counter -


i using liferay service builder jar each plugin portlet. when have insert new record. using below code insert record.

xxx xxx = xxxlocalserviceutil.createxxx(counterlocalserviceutil.increment(xxx.class.getname())); xxx.setvalue(value); xxxlocalserviceutil.addxxx(xxx); 

each table has primary key auto increment. counter local service util calculate own counter value. need each insert's primary key value. in case if first record insert. 1 insert record liferay counter return 101 or 201 according deployment.

this works fine

xxx xxx = new xxximpl(); xxx.setvalue(value); xxxlocalserviceutil.addxxx(xxx); 

i got exact key per hibernate. can not use this. because using jar file of service builder , there not impl class.

service builder xml file:

<entity name="xxx" local-service="true" remote-service="false"> <column name="id" type="long" id-type="increment" primary="true"></column>  <column name="value" type="string" ></column></entity> 

another approach explain:

hi, using service builder plugin portlets. , have custom table having primary key autoincrement. of know there these ways insert records table.

xxx xxx = xxxlocalserviceutil.createxxx(0);  xxx.setvalue(value); xxxlocalserviceutil.addxxx(xxx); 

or

xxx xxx = xxxlocalserviceutil.createxxx(counterlocalserviceutil.increment()); // global increment xxx.setvalue(value); xxxlocalserviceutil.addxxx(xxx); 

or

xxx xxx = xxxlocalserviceutil.createxxx(counterlocalserviceutil.increment(xxx.class.getname())); // increment table specific xxx.setvalue(value); xxxlocalserviceutil.addxxx(xxx); 

in first if want promary key value gets 0, second long value, third incremented value wrt table name. using thid one. if re-deploy service or portlet counter value incresed 101,201,... , can handled setting counter.increment.xxx.class=1 or counter.increment=1.

but want database table incremented value "xxx". there way this. this:

xxx xxx = new xxximpl(); xxx.setvalue(value); xxxlocalserviceutil.addxxx(xxx); 

here can value want database table.

found solution:

xxx xxx = xxxlocalserviceutil.createxxx(0);  xxx.setvalue(value); xxx = xxxlocalserviceutil.addxxx(xxx); 

now have incremented value in xxx. have re-assign object.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -