Transaction Management with Liferay Service
阿新 • • 發佈:2019-01-01
Following are the important points that a Liferay Architect must make note of in order to work with Transactions in Liferay
- The entry point to transaction (start of transaction boundary) in Liferay service is the <Entity>LocalServiceImpl class. Hence, while firing DML oriented methods like update, insert and delete on X Entity from Y do not use make calls to XLocalServiceUtil
or XLocalService as this will result in two transaction boundaries - one for entity X and the other for entity Y. Relate the two entities through service.xml file (one to many or many to many based on your domain model) or else refer one entity in the other
using <reference... in service.xml file. For e.g. if you want to make call on X entity from YLocalServiceImpl then in service.xml file while configuring Y Entity put
<reference entity="X" package-path="com.company.project.X"></reference>
On building the service, you will have access to xPersistence in YLocalServiceImpl. You can now make calls to xPersistence for update, insert and delete - Ensure that your database supports transactions; yes ! this is needless to say but then if you are using MySQL, the database engine other MyISAM does not support transactions. You must use InnoDB as the database engine for your tables.
- As you know Liferay Entity code is generated by service builder and you get an interface called XLocalService. It is this interface which is marked with Transactional Annotation. It is set such that if you throw
PortalException
FROM: http://www.liferayaddicts.net/blogs/-/blogs/transaction-management-with-liferay-service