Skip to content

Conversation

@dreab8
Copy link
Member

@dreab8 dreab8 commented Aug 29, 2024

bulk query execution inside a Transaction

  1. cacheAccess.lockRegion;
  2. cacheAccess.removeAll;
  3. schedule after transaction opertaion (cacheAccess.unlockRegion)
  4. SQL query execution
  5. after transaction triggers cacheAccess.unlockRegion

what happens now for a bulk native query executed ouside a Transaction :

  1. cacheAccess.lockRegion;
  2. cacheAccess.removeAll;
  3. schedule after transaction opertaion (cacheAccess.unlockRegion)
  4. SQL query execution

bulk native query update execution outside Transaction with #8849 (comment)

  1. cacheAccess.lockRegion;
  2. cacheAccess.removeAll;
  3. cacheAccess.unlockRegion
  4. SQL query execution

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Aug 29, 2024

Thanks for your pull request!

This pull request does not follow the contribution rules. Could you have a look?

❌ All commit messages should start with a JIRA issue key matching pattern HHH-\d+
    ↳ Offending commits: [e30e416, de379ff]

› This message was automatically generated.

@dreab8 dreab8 changed the title Update outside transition 2lc Investigating Update outside transition 2lc Aug 29, 2024
@dreab8 dreab8 marked this pull request as draft August 29, 2024 15:47
public void after(SessionFactoryScope scope) {
scope.inTransaction(
session ->
session.createQuery( "delete Customer" ).executeUpdate()

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation

Invoking [QueryProducerImplementor.createQuery](1) should be avoided because it has been deprecated.
public void testUpdateCachedEntity(SessionFactoryScope scope) {
scope.inTransaction(
session ->
session.createNativeQuery( "update Customer set id = id" ).executeUpdate()

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation

Invoking [QueryProducerImplementor.createNativeQuery](1) should be avoided because it has been deprecated.
public void testUpdateCachedOutsideTransaction(SessionFactoryScope scope) {
scope.inSession(
session ->
session.createNativeQuery( "update Customer set id = id" ).executeUpdate()

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation

Invoking [QueryProducerImplementor.createNativeQuery](1) should be avoided because it has been deprecated.
this( DefaultCacheKeysFactory.INSTANCE, properties );
}

public TestCachingRegionFactory(CacheKeysFactory cacheKeysFactory, Properties properties) {

Check notice

Code scanning / CodeQL

Useless parameter

The parameter 'properties' is never used.
@sebersole
Copy link
Member

We talked about this approach as an alternative to https://hibernate.atlassian.net/browse/HHH-18546

@yrodiere had some concerns with the approach in regards to some things done in Hibernate Search. Let's see if he can demonstrate that and we should incorporate his findings, if so.

@yrodiere
Copy link
Member

We talked about this approach as an alternative to https://hibernate.atlassian.net/browse/HHH-18546

@yrodiere had some concerns with the approach in regards to some things done in Hibernate Search. Let's see if he can demonstrate that and we should incorporate his findings, if so.

My concern regarding Hibernate Search was if we generalize the approach of executing "after transaction" operations immediately, since Hibernate Search does that itself. If we do that (which we aren't in this PR), then we'll just have to run Hibernate Search integration tests against the Hibernate ORM snapshots to see if tests still pass, and improvise.

Regarding this patch specifically, I'm discussing it with Andrea right now (though just to give this another pair of eyeballs; you sure know what this implies better than I do).

@dreab8
Copy link
Member Author

dreab8 commented Aug 30, 2024

as suggested by @sebersole probably better to provide a logging in case the operation is executed outside a TX so something like

 if ( !session.isEventSource() ) {
            action.getAfterTransactionCompletionProcess().doAfterTransactionCompletion( true, session );
        }
        else if ( ! session.isTransactionInProgress() ) {
            LOGGING....
            action.getAfterTransactionCompletionProcess().doAfterTransactionCompletion( true, session );
        }
        else {
            session.asEventSource().getActionQueue().addAction( action );
        }

@dreab8 dreab8 closed this Oct 7, 2025
@beikov
Copy link
Member

beikov commented Oct 21, 2025

Just for reference, I believe this was fixed via #9812

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

Successfully merging this pull request may close these issues.

4 participants