留言板

Liferay Service builder-persisting list

thumbnail
Arul Murugan,修改在10 年前。

Liferay Service builder-persisting list

New Member 帖子: 17 加入日期: 13-1-10 最近的帖子
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,修改在10 年前。

RE: Liferay Service builder-persisting list

Liferay Master 帖子: 549 加入日期: 11-6-25 最近的帖子
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,修改在10 年前。

RE: Liferay Service builder-persisting list

New Member 帖子: 17 加入日期: 13-1-10 最近的帖子
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,修改在10 年前。

RE: Liferay Service builder-persisting list

Expert 帖子: 483 加入日期: 10-7-31 最近的帖子
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,修改在8 年前。

RE: Liferay Service builder-persisting list

New Member 帖子: 17 加入日期: 13-1-10 最近的帖子
Thanks for the your reply. i have found the solution for this problem.
thumbnail
Vishal Kumar,修改在8 年前。

RE: Liferay Service builder-persisting list

Regular Member 帖子: 198 加入日期: 12-12-12 最近的帖子
What you have done for this?
thumbnail
Arul Murugan,修改在8 年前。

RE: Liferay Service builder-persisting list

New Member 帖子: 17 加入日期: 13-1-10 最近的帖子
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,修改在8 年前。

RE: Liferay Service builder-persisting list

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
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,修改在8 年前。

RE: Liferay Service builder-persisting list

New Member 帖子: 17 加入日期: 13-1-10 最近的帖子
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.