{"id":16541184,"url":"https://github.com/itzg/try-spring-jta-rollback-listener","last_synced_at":"2025-07-12T15:39:50.589Z","repository":{"id":145318092,"uuid":"200686535","full_name":"itzg/try-spring-jta-rollback-listener","owner":"itzg","description":"This application tests the use of a @TransactionalEventListener in order to perform custom rollback processing.","archived":false,"fork":false,"pushed_at":"2019-08-06T20:55:14.000Z","size":59,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-14T08:52:06.449Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itzg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-05T15:56:35.000Z","updated_at":"2022-01-01T19:47:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"ae0c326b-fb3e-4e42-a7e0-6a27498bde96","html_url":"https://github.com/itzg/try-spring-jta-rollback-listener","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzg%2Ftry-spring-jta-rollback-listener","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzg%2Ftry-spring-jta-rollback-listener/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzg%2Ftry-spring-jta-rollback-listener/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzg%2Ftry-spring-jta-rollback-listener/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itzg","download_url":"https://codeload.github.com/itzg/try-spring-jta-rollback-listener/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241787488,"owners_count":20020099,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T18:54:20.181Z","updated_at":"2025-03-04T04:40:58.220Z","avatar_url":"https://github.com/itzg.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"This application tests the use of a `@TransactionalEventListener` with a phase of `AFTER_ROLLBACK` in order to perform custom rollback processing.\n\nThe listener method is declared as the following in `PublishingService`\n\n```\n  @TransactionalEventListener(phase = TransactionPhase.AFTER_ROLLBACK)\n  public void rollbackInc(IncrementedPublicationsEvent event) {\n    log.debug(\"Rolling back increment of author={} publication\", event.getAuthor());\n    authorStatsService.decrementPublications(event.getAuthor());\n  }\n```\n\nThe event is published as the following in `AuthorStatsService`\n```\n      applicationContext.publishEvent(new IncrementedPublicationsEvent(author));\n```\n\n## Constraint violation during commit skips listener invocation\n\nI consider this a bug in Spring Transactions that the test case `PublishingServiceTest.publish_nullTitle` fails (further confirmation is needed before opening an issue against Spring). \n\nThe rollback listener is normally invoked [at this point in `TransactionAspectSupport`](https://github.com/spring-projects/spring-framework/blob/v5.1.8.RELEASE/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java#L299); however, the constraint violation exception is thrown during the commit [later in the same `invokeWithinTransaction` method, at this point](https://github.com/spring-projects/spring-framework/blob/v5.1.8.RELEASE/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java#L305).\n\nThe following captures some logs and the stack trace around the constraint violation:\n\n```\n2019-08-05 11:01:23.312 ERROR 30778 --- [           main] o.h.i.ExceptionMapperStandardImpl        : HHH000346: Error during managed flush [Validation failed for classes [me.itzg.trying.jtarollbacklistener.entities.Publication] during persist time for groups [javax.validation.groups.Default, ]\nList of constraint violations:[\n\tConstraintViolationImpl{interpolatedMessage='must not be null', propertyPath=title, rootBeanClass=class me.itzg.trying.jtarollbacklistener.entities.Publication, messageTemplate='{javax.validation.constraints.NotNull.message}'}\n]]\n2019-08-05 11:01:23.313 DEBUG 30778 --- [           main] cResourceLocalTransactionCoordinatorImpl : JDBC transaction marked for rollback-only (exception provided for stack trace)\n\njava.lang.Exception: exception just for purpose of providing stack trace\n\tat org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.markRollbackOnly(JdbcResourceLocalTransactionCoordinatorImpl.java:314) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]\n\tat org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:187) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]\n\tat org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$300(JdbcResourceLocalTransactionCoordinatorImpl.java:39) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]\n\tat org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:271) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]\n\tat org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:104) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]\n\tat org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:532) ~[spring-orm-5.1.8.RELEASE.jar:5.1.8.RELEASE]\n\tat org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:746) ~[spring-tx-5.1.8.RELEASE.jar:5.1.8.RELEASE]\n\tat org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:714) ~[spring-tx-5.1.8.RELEASE.jar:5.1.8.RELEASE]\n\tat org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:534) ~[spring-tx-5.1.8.RELEASE.jar:5.1.8.RELEASE]\n\tat org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:305) ~[spring-tx-5.1.8.RELEASE.jar:5.1.8.RELEASE]\n\tat org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) ~[spring-tx-5.1.8.RELEASE.jar:5.1.8.RELEASE]\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.8.RELEASE.jar:5.1.8.RELEASE]\n\tat org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.1.8.RELEASE.jar:5.1.8.RELEASE]\n\tat me.itzg.trying.jtarollbacklistener.services.PublishingService$$EnhancerBySpringCGLIB$$a33d561f.publish(\u003cgenerated\u003e) ~[classes/:na]\n\tat me.itzg.trying.jtarollbacklistener.services.PublishingServiceTest.lambda$publish_nullTitle$2(PublishingServiceTest.java:90) ~[test-classes/:na]\n\tat org.assertj.core.api.ThrowableAssert.catchThrowable(ThrowableAssert.java:62) ~[assertj-core-3.11.1.jar:na]\n\tat org.assertj.core.api.AssertionsForClassTypes.catchThrowable(AssertionsForClassTypes.java:786) ~[assertj-core-3.11.1.jar:na]\n\tat org.assertj.core.api.Assertions.catchThrowable(Assertions.java:1200) ~[assertj-core-3.11.1.jar:na]\n\tat org.assertj.core.api.Assertions.assertThatThrownBy(Assertions.java:1094) ~[assertj-core-3.11.1.jar:na]\n\tat me.itzg.trying.jtarollbacklistener.services.PublishingServiceTest.publish_nullTitle(PublishingServiceTest.java:88) ~[test-classes/:na]\n\n2019-08-05 11:01:23.314 TRACE 30778 --- [           main] cResourceLocalTransactionCoordinatorImpl : ResourceLocalTransactionCoordinatorImpl#afterCompletionCallback(false)\n2019-08-05 11:01:23.314 TRACE 30778 --- [           main] .t.i.SynchronizationRegistryStandardImpl : SynchronizationRegistryStandardImpl.notifySynchronizationsAfterTransactionCompletion(5)\n2019-08-05 11:01:23.315 DEBUG 30778 --- [           main] o.h.e.t.internal.TransactionImpl         : rollback() called on an inactive transaction\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitzg%2Ftry-spring-jta-rollback-listener","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitzg%2Ftry-spring-jta-rollback-listener","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitzg%2Ftry-spring-jta-rollback-listener/lists"}