-
Notifications
You must be signed in to change notification settings - Fork 8k
Interoperability between Quarkus 3 and Hibernate ORM 6.x #17664
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
Conversation
|
I'm facing an error related to the fetching "lazy" collection without session: UPDATE: Workaround described below. Will be resolved in a follow-up tasks. @keycloak/store Do you know what could cause that? |
quarkus/config-api/src/main/java/org/keycloak/config/database/Database.java
Outdated
Show resolved
Hide resolved
|
I've added some comments above. ATM, it's not possible to specify any global Hibernate ORM properties inside the AFAIK, for Quarkus 3, we cannot use As our JPA configuration is based on legacy It would probably be better to consider configuring our default persistence units via the preferred way suggested by the Quarkus team - via Quarkus properties (in |
|
I remember seeing an error similar to this one when the entities were not initializing their collections in the attribute declaration - i.e. when they had But this seems to be something different as it is complaining only about the relationship that is of type |
|
@mabartos - I did some debugging today, and found that the trigger for this behavior is As a workaround, update It seems the only place in the code where this is called. I'll create a minimal reproducer for the Hibernate team, and ask in the Hibernate chat what they think about this behavior. In a later step, we can also evaluate if this refresh is still needed, and if we can eliminate it altogether. UPDATE: If this code snippet works good enough for you, and you choose to commit this code, please create a GitHub issue and add a line comment in the code to track this workaround. |
|
@ahus1 Great! Thank you, I'll try it! Yes, I'll create a separate issue for that and reference it in the commit related to the lazy loading issue. |
db8d2c5 to
201cc6e
Compare
|
@keycloak/store @keycloak/cloud-native |
201cc6e to
b53417b
Compare
model/jpa/src/main/java/org/keycloak/connections/jpa/DefaultJpaConnectionProviderFactory.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for preparing this and making this work. See below for some small changes.
While supporting only JTA for Quarkus is fine, I think this breaks the Undertow setup. When running the KeycloakServer in testsuite/utils, I get an NPE (see below). I assume some of the changes in DefaultJpaConnectionProviderFactory need to be rolled back to make it work again.
Once we support JTA in the Undertow setup and also the model tests, this can be revisited.
I also see a lot of test failures on the GHA run.
Caused by: java.lang.NullPointerException
at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus(JtaStatusHelper.java:59)
at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.isActive(JtaStatusHelper.java:101)
at org.hibernate.engine.transaction.jta.platform.internal.TransactionManagerBasedSynchronizationStrategy.canRegisterSynchronization(TransactionManagerBasedSynchronizationStrategy.java:39)
at org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform.canRegisterSynchronization(AbstractJtaPlatform.java:131)
at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.pulse(JtaTransactionCoordinatorImpl.java:150)
at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.<init>(JtaTransactionCoordinatorImpl.java:91)
at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl.buildTransactionCoordinator(JtaTransactionCoordinatorBuilderImpl.java:37)
at org.hibernate.internal.AbstractSharedSessionContract.<init>(AbstractSharedSessionContract.java:201)
at org.hibernate.internal.SessionImpl.<init>(SessionImpl.java:218)
at org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl.openSession(SessionFactoryImpl.java:1273)
at org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl.openSession(SessionFactoryImpl.java:1161)
at org.hibernate.internal.SessionFactoryImpl.buildEntityManager(SessionFactoryImpl.java:694)
at org.hibernate.internal.SessionFactoryImpl.createEntityManager(SessionFactoryImpl.java:717)
at org.hibernate.internal.SessionFactoryImpl.createEntityManager(SessionFactoryImpl.java:154)
at org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory.createEntityManager(DefaultJpaConnectionProviderFactory.java:93)
at org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory.addSpecificNamedQueries(DefaultJpaConnectionProviderFactory.java:102)
at org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory.lambda$lazyInit$0(DefaultJpaConnectionProviderFactory.java:221)
at org.keycloak.models.utils.KeycloakModelUtils.suspendJtaTransaction(KeycloakModelUtils.java:879)
at org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory.lazyInit(DefaultJpaConnectionProviderFactory.java:143)
at org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory.create(DefaultJpaConnectionProviderFactory.java:87)
at org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory.create(DefaultJpaConnectionProviderFactory.java:66)
at org.keycloak.services.DefaultKeycloakSession.getProvider(DefaultKeycloakSession.java:271)
at org.keycloak.models.jpa.JpaRealmProviderFactory.create(JpaRealmProviderFactory.java:64)
at org.keycloak.models.jpa.JpaRealmProviderFactory.create(JpaRealmProviderFactory.java:40)
quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/Configuration.java
Outdated
Show resolved
Hide resolved
model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProvider.java
Outdated
Show resolved
Hide resolved
|
@ahus1 Thanks for your review. I already have prepared a commit to reverting changes for the I can reproduce the error for GHA tests, as it's still not possible to remove the realm. ATM, when I run clear distribution, I'm able to remove the realm (with the provider realm). However, for tests, after each test class, all test realms should be removed by calling an endpoint for removing the realm. The response code is 409 Conflict, which is quite strange. It's probably caused by the Realms' components again and probably even by some cascading issue? The SQL Error: |
955cf02 to
dc289b3
Compare
--- Quarkus3 branch sync no. 10 (17.3.2023) Resolved conflicts: keycloak/services/src/main/java/org/keycloak/protocol/saml/SamlProtocolUtils.java - Modified --- Quarkus3 branch sync no. 9 (10.3.2023) Resolved conflicts: keycloak/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/kerberos/AbstractKerberosSingleRealmTest.java - Modified keycloak/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/forms/LoginTest.java - Modified --- Quarkus3 branch sync no. 8 (3.3.2023) Resolved conflicts: keycloak/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/SamlClient.java Modified - Modified keycloak/services/src/main/java/org/keycloak/protocol/saml/SamlProtocol.java - Modified keycloak/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionAuthenticator.java - Modified --- Quarkus3 branch sync no. 6 (17.2.2023) Resolved conflicts: keycloak/integration/admin-client/src/main/java/org/keycloak/admin/client/resource/ComponentsResource.java - Modified keycloak/testsuite/utils/src/main/java/org/keycloak/testsuite/KeycloakServer.java - Modified keycloak/services/src/main/java/org/keycloak/protocol/saml/installation/SamlSPDescriptorClientInstallation.java - Modified --- Quarkus3 branch sync no. 5 (10.2.2023) Resolved conflicts: /keycloak/services/src/main/java/org/keycloak/social/google/GoogleIdentityProvider.java Modified - Modified keycloak/services/src/main/java/org/keycloak/social/twitter/TwitterIdentityProvider.java - Modified --- Quarkus3 branch sync no. 4 (3.2.2023) Resolved conflicts: keycloak/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/integration/jaxrs/QuarkusKeycloakApplication.java - Modified --- Quarkus3 branch sync no. 1 (18.1.2023) Resolved conflicts: keycloak/testsuite/client/ClientPoliciesTest.java - Deleted keycloak/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/client/ClientRegistrationTest.java - Modified keycloak/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/JpaModelCriteriaBuilder.java - Modified
--- Quarkus3 branch sync no. 5 (10.2.2023) Resolved conflicts: keycloak/pom.xml - Modified
--- Quarkus3 branch sync no. 7 (27.2.2023) Resolved conflicts: keycloak/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/client/entity/JpaClientEntity.java - Modified keycloak/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/clientScope/entity/JpaClientScopeEntity.java - Modified keycloak/pom.xml - Modified --- Quarkus3 branch sync no. 6 (17.2.2023) Resolved conflicts: keycloak/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/JpaMapStorageProviderFactory.java - Modified --- Quarkus3 branch sync no. 1 (18.1.2023) Resolved conflicts: keycloak/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/hibernate/dialect/JsonbPostgreSQL95Dialect.java - Modified
--- Quarkus3 branch sync #1 (18.1.2023) Resolved conflicts: keycloak/quarkus/runtime/pom.xml - Modified keycloak/quarkus/pom.xml - Modified keycloak/quarkus/deployment/pom.xml - Modified
This reverts commit 2f3fe2b.
433d0a7 to
69ced36
Compare
| return message.toLowerCase().contains("duplicate"); | ||
| }; | ||
|
|
||
| Predicate<Throwable> throwModelDuplicateEx = throwable -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahus1 @vmuzikar
This commit solves the issue of handling exceptions for the JTA tx type.
You can check the original log[1]. There's only a WARN log where the org.hibernate.exception.ConstraintViolationException is thrown, but at the end, we get directly the cause of that (you can see the comment of this method.).
[1] https://gist.github.com/mabartos/e8ea1e3ea945cf0b22748c40c2ce7e63
|
When I tried to upgrade to Quarkus 3.0.0.Beta1 and Hibernate ORM 6.2.0.CR4, I wasn't able to start server due to this ClassCastException: Command: ./keycloak-999.0.0-SNAPSHOT/bin/kc.sh --verbose start-dev |
|
@mabartos: created a new issue: There is also a PR with a workaround: mabartos#126 |
|
Current status for "identifier of an instance changed"
Investigation for a reproducer continues. |
|
There is now a new branch https://github.com/ahus1/keycloak/tree/quarkus3-props which contains the two workarounds. I also found a way to make Keycloak start with Quarkus 3.0.0.Beta1 by tidying up a one-to-many relationship: 53b31b2e5818859188b03ef00ccc711c9177e534 |
|
@ahus1 That's wonderful news, thanks! Does it mean there's a workaround for all Hibernate issues found? Also, would it make sense to close this PR and open another one from your branch? |
I'm not so happy about this one: 822ac249347ac01e581e80726e724bc61e2d2245 - it is a workaround for this case "in the middle of the code", and it might pop up in other places. I'd like to get to the bottom of this to figure how it is caused. The other workaround 93cdc4cd2edd7fab9dcc110437534fb2cd7928ec was changing a Hibernate property, which is a more valid workaround IMHO. At the moment I'm looking at the actions run in my repo to see what is currently failing.
Once we know who will take this forward, there will be a new PR. Once there is a new PR, this old PR will be closed. |
|
The work on this topic continues in #19387 |
No description provided.