Forums de discussion

Liferay Service builder-persisting list

thumbnail
Arul Murugan, modifié il y a 10 années.

Liferay Service builder-persisting list

New Member Publications: 17 Date d'inscription: 10/01/13 Publications récentes
I am struggling to save list of objects in database using liferay service builder methods. Normaly service builder having basic CRUD methods for saving objects.
it will save one by one at time. i want to save list of object at a time. Please advice me!!

]EX: UserLocalServiceUtil.addUser(List<USER>);
thumbnail
Krzysztof Gołębiowski, modifié il y a 10 années.

RE: Liferay Service builder-persisting list

Liferay Master Publications: 549 Date d'inscription: 25/06/11 Publications récentes
Service builder does not support this kind of operations. I think you have to generate your own service (eg. ExtUserLocalServiceUtil) and manually create the method you want. When implementing this method, you need to utilize standard servicebuilder-generated methods - addUser, updateUser etc.

Regards,
KG
thumbnail
Arul Murugan, modifié il y a 10 années.

RE: Liferay Service builder-persisting list

New Member Publications: 17 Date d'inscription: 10/01/13 Publications récentes
Thanks for your replay..!!

Actually i am having entity name as company . I have created model and service classes using service builder.

In CompanyLocalServiceUtil how i can have updateCompany(List<Company>) or addCompany(List<Company>) methods. I think we can create custom sql for saving list of object in database using hiberanate. how i can get hibernate session factory in companyFinderImpl. Please advice me.!!

Thanks in Advance.

Regards
Arul murugan
thumbnail
Harish Kumar, modifié il y a 10 années.

RE: Liferay Service builder-persisting list

Expert Publications: 483 Date d'inscription: 31/07/10 Publications récentes
how i can get hibernate session factory in companyFinderImpl.


CompanyFinderImpl should extends BasePersistenceImpl<Company> implements CompanyFinder

openSession() method will be available in your class from BasePersistenceImpl.
thumbnail
Arul Murugan, modifié il y a 8 années.

RE: Liferay Service builder-persisting list

New Member Publications: 17 Date d'inscription: 10/01/13 Publications récentes
Thanks for the your reply. i have found the solution for this problem.
thumbnail
Vishal Kumar, modifié il y a 8 années.

RE: Liferay Service builder-persisting list

Regular Member Publications: 198 Date d'inscription: 12/12/12 Publications récentes
What you have done for this?
thumbnail
Arul Murugan, modifié il y a 8 années.

RE: Liferay Service builder-persisting list

New Member Publications: 17 Date d'inscription: 10/01/13 Publications récentes
Hi,
My requirement is persisting the list of entity in database using liferay service builder.

In spring 2.5 version the saveorupdateall method was exist and using that we can able to persist list of entity's.

Since liferay 6 onward they are using spring 3.x version so the saveorupdateall method is deprecated but we wanted to use that for that I have created the EntityFinderImpl class in that added one method which accepts list argument.

In this method using the hibernate batch update i am doing the above operation.

public class EmployeeViewMasterFinderImpl extends BasePersistenceImpl<EmployeeViewMaster> implements EmployeeViewMasterFinder{

public void saveList(List employeeList){
Session session = null;
try {
session = openSession();

for ( int i=0; i<employeeList.size(); i++ ) {
Employee customer = employeeList.get(i);
session.save(customer);
if ( i % 20 == 0 ) { //20, same as the JDBC batch size
//flush a batch of inserts and release memory:
session.flush();
session.clear();
}
}

} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
closeSession(session);
}
}




Thanks.
thumbnail
David H Nebinger, modifié il y a 8 années.

RE: Liferay Service builder-persisting list

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
OMG this is just wrong.

Why not use the simpler method in EmployeeViewMasterLocalServiceImpl:

public void updateAll(final List<employeeviewmaster evms) { for (employeeviewmaster evm : updateemployeeviewmaster(evm); } }< code></employeeviewmaster>
<br><br>This way you don't have to worry about caching, hibernate, spring, etc. You just let the SB code do what the SB code is good at doing.
thumbnail
Arul Murugan, modifié il y a 8 années.

RE: Liferay Service builder-persisting list

New Member Publications: 17 Date d'inscription: 10/01/13 Publications récentes
Thanks for your suggestion!!!

Previously i have tried what you have suggested .
But it is taking more time compare to the hibernate batch process that why we have chosen this approach.

Please advice on this .

Thanks.