Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Enable @Transaction on OSGI services
Dear community,
I have created my own service which is an interface as usual from which my implementation inherits.
It gives me the following snippet
But when executing any of the methods of the implementation of this interface, there is no transaction.
Same annotation is being used by the service builder and it works perfectly.
I am afraid it has something to do with the service builder being based on Spring...
Can you please help ?
I have created my own service which is an interface as usual from which my implementation inherits.
It gives me the following snippet
@Transactional(isolation = Isolation.PORTAL, rollbackFor = {
PortalException.class, SystemException.class}, enabled= true)
public interface NotificationService {
public void mymethod();
...
}
But when executing any of the methods of the implementation of this interface, there is no transaction.
Same annotation is being used by the service builder and it works perfectly.
I am afraid it has something to do with the service builder being based on Spring...
Can you please help ?
Well, the difference really is that the SB classes are not OSGi components, they are Spring Beans. As part of the Spring echosystem, the appropriate transaction wrapping occurs.
We see the SB services as OSGi components because Liferay explicitly exposes the Spring Beans defined in a context as component manually.
The easiest solution is to build in your own services as ServiceBuilder no-column entities or even as Fake Entities. This way you get all the benefit of SB (including the txn management) without the corresponding database table(s).
We see the SB services as OSGi components because Liferay explicitly exposes the Spring Beans defined in a context as component manually.
The easiest solution is to build in your own services as ServiceBuilder no-column entities or even as Fake Entities. This way you get all the benefit of SB (including the txn management) without the corresponding database table(s).
Hi David,
If I correctly understood your answer, I cannot setup transactionnal methods outside of the service builder.
Thank you !
If I correctly understood your answer, I cannot setup transactionnal methods outside of the service builder.
Thank you !
Eric COQUELINWell, I guess you can. but it's complicated (TM)
If I correctly understood your answer, I cannot setup transactionnal methods outside of the service builder.
ServiceBuilder has it all implemented already, and it's by far easier (and more futureproof / easier to maintain) to just hook into the same mechanism than to come up with your own.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™