掲示板

Transaction rollback covers only operations on entities from plugins env

14年前 に Krzysztof Makowski によって更新されました。

Transaction rollback covers only operations on entities from plugins env

Junior Member 投稿: 31 参加年月日: 09/05/08 最新の投稿
We have such situation:

Our entities:

ExtUser
UserSkill

Liferay entities:
Address,
Contact,
Phone


We want to update ZplUser which is a facade containing all those entities. For update we are using ZplUserLocalServiceImpl class.

this class contains such method


public ZplUser updateZplUser(long companyId, ZplUser zplUser) throws SystemException, PortalException{
        phoneLocalService.update(zplUser.getMobilePhone());
        addressLocalService.update(zplUser.getAddress());
        extUserLocalService.update(zplUser.getExtUser());
        userSkillLocalService.addUserSkill(100,100);
        userSkillLocalService.setUserSkills(zplUser.getUser().getUserId(), zplUser.getSkillIds());
        return zplUser;
}


in method setUserSkills(...) we hardcoded throwing a SystemException to test if all operations that are before setUserSkills would be rolled back.

Unfortunatelly only one operation is rolled back - addUserSkill(100,100). All other operations ARE NOT ROLLED BACK.

What we are doing wrong? What to do to achieve rollbacking of all five operations?
14年前 に Krzysztof Makowski によって更新されました。

RE: Transaction rollback cover only operations on one entity

Junior Member 投稿: 31 参加年月日: 09/05/08 最新の投稿
We are using postgressql so it is not the problem with MySQL MyISAM/InnoDB tables.
14年前 に Krzysztof Makowski によって更新されました。

RE: Transaction rollback cover only operations on one entity

Junior Member 投稿: 31 参加年月日: 09/05/08 最新の投稿
Some more findings on this topic:

After monitoring of debug logs for HibernateTransactionManager we found out that liferay is creating new transaction for operation phoneLocalService.updatePhone(...) and for addressLocalService.updateAddress(...).

Is it possible that our entities (Created by service builder in plugins environment) are treated by transaction manageer in other way than Liferay out of box entities?
thumbnail
14年前 に Mika Koivisto によって更新されました。

RE: Transaction rollback cover only operations on one entity

Liferay Legend 投稿: 1519 参加年月日: 06/08/07 最新の投稿
You will need JTA to do distributed transactions from plugins. By default Liferay uses HibernateTransactionManager which will only manage transactions within one context. You are trying to do transactions between portal context and your plugin context.
14年前 に Krzysztof Makowski によって更新されました。

RE: Transaction rollback cover only operations on one entity

Junior Member 投稿: 31 参加年月日: 09/05/08 最新の投稿
Thanks for the answer.

I am intersted in using JTA because we do a lot of programming in plugin environment.

I was looking for a wiki article or blog article describing how to switch liferay from HibernateTransactionManager to JtaTransactionManager, but it seems that this problem is not described anywhere. Could you explain what should I do to switch to JTA in Liferay 5.2.3?

I only found in trunk version of portal.properties info that it will be possible in the next version of liferay (6.0) to switch to JTA by changing just few lines of properties file. But I wonder if this option is available only in application servers like Glassfish or maybe it is available also in Tomcat servlet container. Could you provide some more info on this subject?
13年前 に Rick Dangerous によって更新されました。

RE: Transaction rollback cover only operations on one entity

Junior Member 投稿: 61 参加年月日: 11/01/25 最新の投稿
Mika Koivisto:
You will need JTA to do distributed transactions from plugins. By default Liferay uses HibernateTransactionManager which will only manage transactions within one context. You are trying to do transactions between portal context and your plugin context.


If I need transactions across two different portlets...for example:
- A portlet, with his own service layer and own database table, that upload documents to DocumentLibrary, and then saves document id at his own table.

need JTA too?