What is the use of @Transactional with JPA and Hibernate?

后端 未结 4 552
半阙折子戏
半阙折子戏 2021-02-09 04:24

I\'m learning about how to create REST API with JPA and Hibernate and a MySQL database and I see this @Transactional annotation. Can someone explain what is the use of this anno

4条回答
  •  情书的邮戳
    2021-02-09 05:00

    Generally the @Transactional annotation is written at the service level.

    It is used to combine more than one writes on a database as a single atomic operation.

    When somebody call the method annotated with @Transactional all or none of the writes on the database is executed.

    In the case of read operations it is not useful and so it is in case of a single atomic write. You are using it in a single read (select) so adding or removing the @Transactional annotation has no impact.

提交回复
热议问题