-
-
Notifications
You must be signed in to change notification settings - Fork 953
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
'HibernateException: No Session found for current thread' for readOnly dataSource #10556
Comments
I suggest you upgrade to GORM 6.1 and use the new
|
I will update and check. Just one notice our domain classes defined in plugin and in domain classes we defined already our datasource mapping to rimm we should repeat rimm in our services also? Its looks like duplication and and creating coupling also I guess |
Well what you have now is it creating a transaction for default connection, so your service is not actually binding the correct transaction. The only reason it worked before is because Grails was binding a session (but not creating a transaction) for your secondary data source |
Thanks for explanation, btw I updated to GORM 6.1.0 and have following exception for some reason its trying to use JPA configuration:
|
Interesting, could you provide an example that reproduces? As a workaround please add: @EnableAutoConfiguration(excludes=[org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration]) To your |
Here is another exception after excluding JPA
Will try to create sample project and reproduce issue. Thanks. |
one more question reg. the original issue (readOnly dataSources excluded from ChainedTransactionManager): what is the recommended pattern for a service that writes to one datasources and reads from other datasources?
personally, i would like to at least have the option to configure the legacy |
@armsargis Sounds like you are using Hibernate 5.2, please downgrade to Hibernate 5.1.x until this issue is resolved |
@zyro23 The last one, using services to wrap the logic that accessed the second data source. Note that ChainedTransactionManager will be disabled by default in Grails 3.3 and above with an option to re-enable it. Binding a session for every data source for every transaction is not efficient. However, we can add an option to re-enable ChainedTransactionManager for readOnly data sources. I will see what we can do about that. |
Thanks @graemerocher btw I think nice to have option to re-enable it to have a time to organize migration considering that usually usages such code in many plugins and many applications |
Looking at the code it seems there is already an option to re-enable by specifying the dataSource as transactional: rimm:
pooled: true
jmxExport: true
driverClassName: org.h2.Driver
transactional: true # add this line
readOnly: true
username: sa
password: |
After updating from grails 3.2.7 to grails 3.2.8 I have exception:
and here is service definition:
service creating DetachedCriteria for one domain class and executed query.
Domain using datasource which is marked as readOnly:
if I remove readOnly from dataSource definition everything works as before. I guess issue related with commit: f17ad39
Environment Information
The text was updated successfully, but these errors were encountered: