1

I have to use hibernate along with spring boot. Is it recommended to use JTA transaction manager in this stack?

If JTA is recommended, how to access current session programmatically in controller or service layer ? with example will be more helpful.

Krishna
  • 393
  • 2
  • 3
  • 18
  • Which transaction manager you use doesn't change how you get the current session (or rather EntityManager). Do you really need JTA or can you do without? – M. Deinum Jul 29 '20 at 07:24
  • I am thinking to use spring's JtaTransactionManager. Reason for JTA is, as per requirement, 2 resources to be managed within single transaction scope. – Krishna Jul 30 '20 at 05:06

1 Answers1

1

As spring documentation says:

Typically, you need an application server’s JTA capability only if your application needs to handle transactions across multiple resources, which is not a requirement for many applications.

And according to spring boot documentation:

Spring Boot supports distributed JTA transactions across multiple XA resources by using either an Atomikos or Bitronix embedded transaction manager. JTA transactions are also supported when deploying to a suitable Java EE Application Server.

When a JTA environment is detected, Spring’s JtaTransactionManager is used to manage transactions. Auto-configured JMS, DataSource, and JPA beans are upgraded to support XA transactions. You can use standard Spring idioms, such as @Transactional, to participate in a distributed transaction.

As for your second question you can have a look at this answer.

SternK
  • 11,649
  • 22
  • 32
  • 46