Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GORM multitenancy - no transaction is in progress #618

Closed
Goliath opened this issue Sep 15, 2022 · 1 comment · Fixed by #659
Closed

GORM multitenancy - no transaction is in progress #618

Goliath opened this issue Sep 15, 2022 · 1 comment · Fixed by #659
Assignees

Comments

@Goliath
Copy link

Goliath commented Sep 15, 2022

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)
@puneetbehl puneetbehl self-assigned this Sep 20, 2022
@jrechet
Copy link
Contributor

jrechet commented Feb 4, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants