Skip to content

Fix auto-configuration to apply a shared container entity manager instance for GraphQLJPASchemaBuilder #380

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

Merged
merged 7 commits into from
Nov 17, 2023

Conversation

igdianov
Copy link
Collaborator

@igdianov igdianov commented Nov 10, 2023

To fix intermittent incorrect empty query results due to Hibernate query result list containing proxied entities when executing query requests concurrently.

The GraphQLJPAQueryBuilder was not using the Shared Entity Manager proxy provided by Spring ORM. Instead, it was configured using a static instance backed by non-thread safe Hibernate Session created by the entity manager factory method.

A Spring shared EntityManager will behave just like an EntityManager fetched from an application server's JNDI environment, as defined by the JPA specification. It will delegate all calls to the current transactional EntityManager already attached to a thread per transaction, if any; otherwise it will fall back to a newly created EntityManager per operation request.

The functional tests worked fine, but not concurrently. It also worked in Hibernate 5 by luck and stopped working in Hibernate 6 after upgrade to Spring Boot 3

@igdianov igdianov self-assigned this Nov 10, 2023
@igdianov igdianov added the bug label Nov 10, 2023
Copy link

codecov bot commented Nov 10, 2023

Codecov Report

Attention: 54 lines in your changes are missing coverage. Please review.

Comparison is base (d0957ec) 76.11% compared to head (6b83668) 75.53%.
Report is 1 commits behind head on master.

Files Patch % Lines
...figure/TransactionalDelegateExecutionStrategy.java 29.54% 31 Missing ⚠️
.../jpa/query/schema/impl/GraphQLJpaQueryFactory.java 51.51% 13 Missing and 3 partials ⚠️
...schema/impl/GraphQLJpaToManyMappedBatchLoader.java 33.33% 3 Missing and 1 partial ⚠️
...GraphQLJpaQueryGraphQlSourceAutoConfiguration.java 88.88% 1 Missing ⚠️
...nfigure/GraphQLSchemaBuilderAutoConfiguration.java 93.33% 1 Missing ⚠️
...jpa/query/schema/impl/GraphQLJpaSchemaBuilder.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #380      +/-   ##
============================================
- Coverage     76.11%   75.53%   -0.59%     
- Complexity     1133     1150      +17     
============================================
  Files            75       76       +1     
  Lines          5083     5178      +95     
  Branches        732      739       +7     
============================================
+ Hits           3869     3911      +42     
- Misses          890      940      +50     
- Partials        324      327       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@igdianov igdianov changed the title Fix intermittent incorrect query results due to Hibernate proxies Fix intermittent incorrect empty query results due to Hibernate proxies Nov 10, 2023
@igdianov igdianov changed the title Fix intermittent incorrect empty query results due to Hibernate proxies Fix auto-configuration to apply a shared container entity manager instance for GraphQLJPASchemaBuilder Nov 17, 2023
@igdianov igdianov merged commit f19c603 into master Nov 17, 2023
@igdianov igdianov deleted the fix-incorrect-query-results-with-proxies branch November 27, 2023 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant