Fórum

Liferay Service builder-persisting list

thumbnail
Arul Murugan, modificado 10 Anos atrás.

Liferay Service builder-persisting list

New Member Postagens: 17 Data de Entrada: 10/01/13 Postagens Recentes
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, modificado 10 Anos atrás.

RE: Liferay Service builder-persisting list

Liferay Master Postagens: 549 Data de Entrada: 25/06/11 Postagens Recentes
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, modificado 10 Anos atrás.

RE: Liferay Service builder-persisting list

New Member Postagens: 17 Data de Entrada: 10/01/13 Postagens Recentes
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, modificado 10 Anos atrás.

RE: Liferay Service builder-persisting list

Expert Postagens: 483 Data de Entrada: 31/07/10 Postagens Recentes
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, modificado 8 Anos atrás.

RE: Liferay Service builder-persisting list

New Member Postagens: 17 Data de Entrada: 10/01/13 Postagens Recentes
Thanks for the your reply. i have found the solution for this problem.
thumbnail
Vishal Kumar, modificado 8 Anos atrás.

RE: Liferay Service builder-persisting list

Regular Member Postagens: 198 Data de Entrada: 12/12/12 Postagens Recentes
What you have done for this?
thumbnail
Arul Murugan, modificado 8 Anos atrás.

RE: Liferay Service builder-persisting list

New Member Postagens: 17 Data de Entrada: 10/01/13 Postagens Recentes
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, modificado 8 Anos atrás.

RE: Liferay Service builder-persisting list

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
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, modificado 8 Anos atrás.

RE: Liferay Service builder-persisting list

New Member Postagens: 17 Data de Entrada: 10/01/13 Postagens Recentes
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.