grails / gorm-hibernate5

GORM for Hibernate 5

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GORM multitenancy - no transaction is in progress

Goliath opened this issue · comments

Steps to Reproduce

Update datasource configuration in sample app:

dataSource:
  pooled: true
  jmxExport: true
  driverClassName: org.h2.Driver
  dbCreate: create-drop
  url: jdbc:h2:mem:books;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE

dataSources:
    moreBooks:
        dbCreate: create-drop
        url: jdbc:h2:mem:books;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
    evenMoreBooks:
        dbCreate: create-drop
        url: jdbc:h2:mem:books;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE

Start the official sample app.
Pick any tenant try to save the book.

Expected Behaviour

Book is saved

Actual Behaviour

Exception is thrown: javax.persistence.TransactionRequiredException: no transaction is in progress

Environment Information

Ubuntu 20.04
GORM Version: shipped with grails 5.1.8
Grails Version 5.1.8 provided sample and observed in the newest version (no sample provided)
JDK Version: 11.0.14-zulu

Example Application

https://github.com/grails/gorm-hibernate5/tree/7.3.x/examples/grails3-schema-per-tenant

Stack Trace:

javax.persistence.TransactionRequiredException: no transaction is in progress
	at org.hibernate.internal.AbstractSharedSessionContract.checkTransactionNeededForUpdateOperation(AbstractSharedSessionContract.java:445)
	at org.hibernate.internal.SessionImpl.checkTransactionNeededForUpdateOperation(SessionImpl.java:3483)
	at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1399)
	at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1394)
	at org.springframework.orm.hibernate5.SessionFactoryUtils.flush(SessionFactoryUtils.java:113)
	at org.springframework.orm.hibernate5.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:95)
	at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:97)
	at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:916)
	at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:727)
	at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:711)
	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:152)
	at grails.gorm.transactions.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:91)
	at example.$BookServiceImplementation.$mt__saveBook(BookService.groovy)

Hi,
I've noticed the same problem. We can't manage to use the @transactional annotation in schema multitenancy mode.

I wrote few tests to show what we are trying to do :

https://github.com/jrechet/grails-multitenant-exemple