codeconsole opened a new pull request, #15745: URL: https://github.com/apache/grails-core/pull/15745
## Depends on #15744 (stacked PR) This is stacked on top of #15744 (opt-in MongoDB transactions). Until #15744 merges, the diff here also includes its commit — please review/merge **#15744 first**, after which this PR reduces to just the new interop module. The unified transaction here relies on the `ClientSession` introduced by #15744. ## What A new **opt-in** module, `grails-data-mongodb-spring-data`, that lets GORM for MongoDB and Spring Data MongoDB run side by side over the **same** `MongoClient`, database and codecs — and, within a single `@Transactional` method, the **same** MongoDB transaction. When the module and `spring-data-mongodb` are on the classpath of a Spring Boot app that has a GORM `MongoDatastore`, it auto-configures over GORM's connection: - a `MongoDatabaseFactory` bound to GORM's client + default database (it does **not** close GORM's client), - a `MongoTemplate` (+ `MappingMongoConverter`) sharing the driver codec registry, - a primary `transactionManager` (`GormSharedSessionMongoTransactionManager`) that binds GORM's `ClientSession` into Spring Data, so a GORM `save()` and a `MongoTemplate`/repository write in one `@Transactional` method commit or roll back together. Unified transactions require GORM server-side transactions (`grails.mongodb.transactional = true`, from #15744). Spring Data repositories are enabled the usual way via `@EnableMongoRepositories`, on a package separate from GORM `@Entity` classes. ## Boundary Only the connection, codecs and (within a transaction) the `ClientSession` are shared; the two object-mapping models stay separate (GORM maps `@Entity`; Spring Data maps its own documents). Sharing the session reaches Spring Data's package-private `MongoResourceHolder`, so a small helper lives in package `org.springframework.data.mongodb` — verified against the Spring Data MongoDB 5.x line in Spring Boot 4, class-path only (not JPMS module-path). A single flat transaction (`PROPAGATION_REQUIRED`) is supported; `REQUIRES_NEW`/`NESTED` are not. ## Tests - `UnifiedMongoTransactionSpec` — GORM + `MongoTemplate` commit and roll back together on one session; coexistence read; sequential transactions without session/holder leaks; a Spring Data repository over the shared connection; auto-config wiring; the shared factory does not close GORM's client. - `GormSpringDataSessionSupportSpec` — coupling smoke test that fails loudly if the Spring Data internal shape changes. Targets `8.0.x`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
