Difference between JTA and Spring @Transactional comments

I started using Spring @Transactional annotation, and it provides a lot of convenience for transaction management. However, using this annotation in our code now makes us depend on Spring. I know that in JPA style there is a javax persistence package where we can split the code into all kinds if JPA annotations, but since they all come from javax.persistence , our code does not depend on any particular implementation or ORM.

I think my question is if there are any similar annotations for transactional materials. I found the javax jta package, but I'm not sure there really are general annotations that Spring can implement. Basically, I'm just wondering if there are any general annotations like javax that we can use to manage transactional functions so that we are not dependent on Spring.

+6
source share
1 answer

I don’t think JavaEE 6 offers transaction demarcation annotations like Spring, for example. The closest analogue, I think, is to use a non-EJB beans session, which by their nature are transactional but clearly not demarcated as such (someone, please correct me if I'm wrong).

This is your call regarding which API you have chosen to connect your code to. The advantage of using Spring @Transactional is that you are not dependent on the particular transaction API used ( @Transactional can work with JTA, JPA, Hibernate or raw JDBC transactions without changing the code). But of course you are attached to Spring.

If the annotation style is what you want, I don't see an alternative to Spring unless you want to fully embrace JavaEE and use EJB 3.x annotations.

+9
source

Source: https://habr.com/ru/post/915224/


All Articles