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

javax.persistence.TransactionRequiredException: no transaction is in progress #175

Closed
petrosbaltzis opened this issue Oct 11, 2018 · 8 comments

Comments

@petrosbaltzis
Copy link

I am getting the exception above when I try to save an auditable domain.
Grails version: 3.3.2
Grails-audit-logging-plugin version: 3.0.1

On the service level, I use the @transactional annotation, therefore, in theory, there is an open transaction.
I have tried to use different propagations (REQUIRED, REQUIRED_NEW) but I got the same exception.

I wonder if it is something wrong in my configuration or if it is a potential bug.

@robertoschwald
Copy link
Member

Should work. See #161

@jkrshw
Copy link

jkrshw commented Oct 16, 2018

The "javax.persistence.TransactionRequiredException" is caused by a change in hibernate 5.2 that now requires a transaction on all flushing updates

It seems the transactional behaviour of the plugin is not working as expected, I have created a branch with failing test that shows the audit logs are persisted even if the transaction is rolled back.

The existing test "Test failed insert logging" doesn't catch this as grails validation prevents the insert from ever being executed.

Alternatively, updating to hibernate 5.2.17 will cause all integration tests to fail with "javax.persistence.TransactionRequiredException"

You may have more experience with grails application events, I can't tell from the documentation how transaction propagation is meant to work for application events.

@longwa
Copy link
Collaborator

longwa commented Feb 27, 2019

The events aren't within the existing transaction as they are triggered as part of the flush itself. The solution is to use the same approach as hibernate-envers, which is to register a callback which is executed on transaction commit to write the entries. This is a requirement for the plugin to work correctly in Grails 4.0 as it requires Hibernate 5.4+.

I'm working on a fix.

@luke10
Copy link

luke10 commented Mar 4, 2019

Just to add my 2c, I'm also blocked by this issue as I am using a more recent version of Hibernate for other purposes. For now, I've avoided the issue by setting hibernate.allow_update_outside_transaction = true but this must never make it to production..

@wkulik
Copy link

wkulik commented Oct 14, 2019

I also have the allow update outside transaction set to true for now. I am currently using Grails 3.3. Are there any updates upcoming or suggested workarounds that can be used in a Production environment, or should I use a different auditing method?

@robertoschwald
Copy link
Member

We are working on the tests for longwa's approach. See branch 4.0.0_wip

@nitinmahawadiwar
Copy link

I am able to fix the issue as commented by @luke10 , but then what should be ideal solution for Production environment.

robertoschwald pushed a commit that referenced this issue May 16, 2020
@robertoschwald
Copy link
Member

As we are not ready with the new approach, yet, we use a workaround which spawns own transaction. Give release 3.0.6 a try.

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

No branches or pull requests

7 participants