File tree Expand file tree Collapse file tree 3 files changed +25
-5
lines changed
persistence-modules/spring-boot-persistence-5/src/main/java/com/baeldung/rollbackonly Expand file tree Collapse file tree 3 files changed +25
-5
lines changed Original file line number Diff line number Diff line change 1- package com .baeldung .transactional . rollback ;
1+ package com .baeldung .rollbackonly . article ;
22
3- import jakarta .annotation .Nonnull ;
43import jakarta .persistence .Column ;
54import jakarta .persistence .Entity ;
65import jakarta .persistence .GeneratedValue ;
1312@ Data
1413@ Entity
1514@ NoArgsConstructor
16- class Article {
15+ public class Article {
1716
1817 @ Id
1918 @ GeneratedValue (strategy = GenerationType .SEQUENCE )
Original file line number Diff line number Diff line change 1- package com .baeldung .transactional . rollback ;
1+ package com .baeldung .rollbackonly . article ;
22
33import org .springframework .data .jpa .repository .JpaRepository ;
44import org .springframework .stereotype .Repository ;
55
6+
67@ Repository
7- interface ArticleRepo extends JpaRepository <Article , Long > {
8+ public interface ArticleRepo extends JpaRepository <Article , Long > {
89}
Original file line number Diff line number Diff line change 1+ package com .baeldung .rollbackonly .audit ;
2+
3+ import org .springframework .stereotype .Component ;
4+ import org .springframework .transaction .annotation .Propagation ;
5+ import org .springframework .transaction .annotation .Transactional ;
6+
7+ @ Component
8+ public class AuditService {
9+
10+ private final AuditRepo auditRepo ;
11+
12+ @ Transactional (propagation = Propagation .REQUIRES_NEW )
13+ public void saveAudit (String action , String status , String message ) {
14+ auditRepo .save (new Audit (action , status , message ));
15+ }
16+
17+ public AuditService (AuditRepo auditRepo ) {
18+ this .auditRepo = auditRepo ;
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments