事务控制
2014-01-03 23:29
204 查看
原文:http://www.liferayaddicts.net/blogs/-/blogs/transaction-management-with-liferay-service
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. <reference... tag is exactly for this reason. You can also include something like <reference
entity="User" package-path="com.liferay.portal"></reference> to get the userPersistence object in your Entity. Then the calls to your entity and userPersistence will be the part of same transaction. In other words, updates to your tables and
user_ table will be part of same transaction - either everything will commit or evrerything will be rolledback on encounter PortalException or SystemException.
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 useInnoDB 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 or SystemException from
any of the methods, Hibernate Transaction Manager will rollback the transaction. Hence on violation of any business rule in the custom business-service method of XLocalServiceImpl if you want to rollback the transaction, you must throw either PortalException
or SystemException.
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. <reference... tag is exactly for this reason. You can also include something like <reference
entity="User" package-path="com.liferay.portal"></reference> to get the userPersistence object in your Entity. Then the calls to your entity and userPersistence will be the part of same transaction. In other words, updates to your tables and
user_ table will be part of same transaction - either everything will commit or evrerything will be rolledback on encounter PortalException or SystemException.
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 useInnoDB 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 or SystemException from
any of the methods, Hibernate Transaction Manager will rollback the transaction. Hence on violation of any business rule in the custom business-service method of XLocalServiceImpl if you want to rollback the transaction, you must throw either PortalException
or SystemException.
相关文章推荐
- mysql数据库+java实现事务控制工作笔记
- (接上例)JPA中实现增删改查及事务控制
- 事务控制代码示例
- 记一次数据库事务的并发同步控制
- JDBC事务控制 菜鸟入门
- SpringMVC与Mybatis集合实现调用存储过程、事务控制实例
- 在C#中使用COM+实现事务控制
- 事务及并发控制(锁,死锁,恢复)
- mysql之控制台下的事务控制
- C#中跨库事务控制(二)
- 数据库并发事务控制 二:mysql数据库锁机制
- Grails中Domain对象的事务控制及同一对象的重复提交
- 数据库并发事务控制四:postgresql数据库的锁机制
- Spring入门5:事务控制
- 事务控制
- java中Spring嵌套事务控制
- InnoDB---事务和并发控制相关的文件
- 触发器 事务控制 sql MODE mysql分区
- 触发器 事务控制 sql MODE mysql分区
- EJB重温总结--事务控制