Fórum

Liferay Service Builder : Transaction management

Koffi AGHOSTO, modificado 7 Anos atrás.

Liferay Service Builder : Transaction management

Junior Member Postagens: 67 Data de Entrada: 27/05/14 Postagens Recentes
Hello everybody,

I have a serious problem with Service builder transaction. When I get java.sql.SQLException, the data is not rollbacking.

I know that Liferay service builder rollback only when it is SystemException or PortalException. So my question is how can I force service
builder to rollback for SQLException ?

My environment :
Liferay 6.2 EE SP11
MySQL - JBOSS

Thank you in advanced;
Koffi
Martin Vaněk, modificado 7 Anos atrás.

RE: Liferay Service Builder : Transaction management

New Member Postagens: 11 Data de Entrada: 12/03/16 Postagens Recentes
Hello Koffi,

as far as I know service builder methods where SQLException could happen are wrapping SQL exception into SystemException so there should be ne problem.

Is there ay chance you use MyISAM as database engine? This engine doesn't support transaction so make sure you have that checked.

Maybe would be enough to cover your critical block into catch / try and then wrap it into SystemException and then throw it?

You could solve this issue from outside of service, you could maybe use TransactionInvokerUtil and set up the TransactionAttribue to rollback for SQLException. (I am not sure about how much this thing should be used, but it works for me to do multiple service methods and something between in one transcation).

Apart from that you can fiddle with transaction manager via property transaction.manager.impl in portal.properties but I havent done this yet so I dont know.

I hope at least something helps even a little.
Koffi AGHOSTO, modificado 7 Anos atrás.

RE: Liferay Service Builder : Transaction management

Junior Member Postagens: 67 Data de Entrada: 27/05/14 Postagens Recentes
Hello Martin,

First of all, I want to thank you a lot for your answer.

I put all my code in one try/catch (Throwable e) and then I throw SystemException, but it doesn't do the rollback. After searching, I noticed that the SQLException is thrown on the commit of the global transaction, so the error occurs after my code execution (after the try/catch).

I forget to precise that, I am not in the same schema of database with liferay tables, I am connect to another schema, I don't know if I must do something in this case to activate the rollback?

I will try your suggestion and will back to you soon,

Thank you.
Koffi
Martin Vaněk, modificado 7 Anos atrás.

RE: Liferay Service Builder : Transaction management

New Member Postagens: 11 Data de Entrada: 12/03/16 Postagens Recentes
I have not worked with different schema than Liferays so I sadly cannot help you with that.