Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Krzysztof Makowski
Transaction rollback covers only operations on entities from plugins env
February 15, 2010 7:32 AM
Answer

Krzysztof Makowski

Rank: Junior Member

Posts: 31

Join Date: May 8, 2009

Recent Posts

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

 1
 2public ZplUser updateZplUser(long companyId, ZplUser zplUser) throws SystemException, PortalException{
 3        phoneLocalService.update(zplUser.getMobilePhone());
 4        addressLocalService.update(zplUser.getAddress());
 5        extUserLocalService.update(zplUser.getExtUser());
 6        userSkillLocalService.addUserSkill(100,100);
 7        userSkillLocalService.setUserSkills(zplUser.getUser().getUserId(), zplUser.getSkillIds());
 8        return zplUser;
 9}


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?
Krzysztof Makowski
RE: Transaction rollback cover only operations on one entity
February 15, 2010 6:22 AM
Answer

Krzysztof Makowski

Rank: Junior Member

Posts: 31

Join Date: May 8, 2009

Recent Posts

We are using postgressql so it is not the problem with MySQL MyISAM/InnoDB tables.
Krzysztof Makowski
RE: Transaction rollback cover only operations on one entity
February 15, 2010 7:15 AM
Answer

Krzysztof Makowski

Rank: Junior Member

Posts: 31

Join Date: May 8, 2009

Recent Posts

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?
Mika Koivisto
RE: Transaction rollback cover only operations on one entity
February 15, 2010 7:25 AM
Answer

Mika Koivisto

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1512

Join Date: August 7, 2006

Recent Posts

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.
Krzysztof Makowski
RE: Transaction rollback cover only operations on one entity
February 16, 2010 3:07 AM
Answer

Krzysztof Makowski

Rank: Junior Member

Posts: 31

Join Date: May 8, 2009

Recent Posts

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?
Moisés Belda
RE: Transaction rollback cover only operations on one entity
January 25, 2011 3:22 AM
Answer

Moisés Belda

Rank: Junior Member

Posts: 61

Join Date: January 25, 2011

Recent Posts

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?