0

I have questing regarding JPA persistence. I want to change values of specific column (for e.g. 1 to 2), and fetch corresponding rows further (which are having column value 2). If other service gives some error, I want to revert column values to 1.

Can we do this in JPA?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Stephan
  • 91
  • 1
  • 1
  • 6

2 Answers2

0

You can use @Transactional annotation to your method. so, you can change value from 1 to 2. Then fetch corresponding rows. Anywhere exception happens, it will be reverted back to 1.

Sridhar Patnaik
  • 970
  • 1
  • 13
  • 24
0

If you use spring data JPA, try something like that:

@Transactional
@Modifying
@Query("UPDATE ...")
Michael
  • 72
  • 3
  • 9