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

Hibernate-Reactive: ClassCastException EmbeddableInitializerImpl to ReactiveInitializer #43326

Closed
ITrium-Salah opened this issue Sep 16, 2024 · 22 comments · Fixed by #43348
Closed
Labels
area/hibernate-reactive Hibernate Reactive kind/bug Something isn't working
Milestone

Comments

@ITrium-Salah
Copy link

Describe the bug

When migration from Quarkus 3.13.3 to any quarkus 3.14.X version a classe cast expression occured when using @Embeddable/@EmbeddedId.

Expected behavior

No exception should be thrown.

Actual behavior

java.lang.ClassCastException: class org.hibernate.sql.results.graph.embeddable.internal.EmbeddableInitializerImpl cannot be cast to class org.hibernate.reactive.sql.results.graph.ReactiveInitializer (org.hibernate.sql.results.graph.embeddable.internal.EmbeddableInitializerImpl and org.hibernate.reactive.sql.results.graph.ReactiveInitializer are in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @10feca44)
    at org.hibernate.reactive.sql.results.graph.entity.internal.ReactiveEntityInitializerImpl.initializeId(ReactiveEntityInitializerImpl.java:748)
    at org.hibernate.reactive.sql.results.graph.entity.internal.ReactiveEntityInitializerImpl.reactiveResolveKey(ReactiveEntityInitializerImpl.java:625)
    at org.hibernate.reactive.sql.results.graph.entity.internal.ReactiveEntityInitializerImpl.reactiveResolveKey(ReactiveEntityInitializerImpl.java:605)
    at org.hibernate.reactive.sql.results.graph.entity.internal.ReactiveEntityInitializerImpl.reactiveResolveKey(ReactiveEntityInitializerImpl.java:56)
    at org.hibernate.reactive.sql.results.internal.ReactiveStandardRowReader.resolveKey(ReactiveStandardRowReader.java:383)
    at org.hibernate.reactive.sql.results.internal.ReactiveStandardRowReader.lambda$coordinateInitializers$28(ReactiveStandardRowReader.java:376)

How to Reproduce?

My code is simple.

class A extends PanacheEntityBase{
    @EmbeddedId 
    B id;
 
}
@Embeddable
class B implements Serializable{
    @Column(nullable=false)
    String c1;
    @Column(nullable=false)
    String c2;
}

Http Route
return A.listAll();

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

3.14.4

Build tool (ie. output of mvnw --version or gradlew --version)

mvn 3.9.5

Additional information

Work around: Use @IdClass

@ITrium-Salah ITrium-Salah added the kind/bug Something isn't working label Sep 16, 2024
Copy link

quarkus-bot bot commented Sep 16, 2024

/cc @DavideD (hibernate-reactive), @gavinking (hibernate-reactive)

@quarkus-bot quarkus-bot bot added the area/hibernate-reactive Hibernate Reactive label Sep 16, 2024
@DavideD
Copy link
Contributor

DavideD commented Sep 16, 2024 via email

@DavideD
Copy link
Contributor

DavideD commented Sep 19, 2024

This should be fixed by #43348

@tmonney
Copy link

tmonney commented Nov 1, 2024

Any chance to have this backported to 3.15?

@yrodiere
Copy link
Member

yrodiere commented Nov 4, 2024

Yes it will be, as indicated on the PR:

Image

@gsmet gsmet modified the milestones: 3.16.0.CR1, 3.15.2 Nov 13, 2024
@mubashirrbaig
Copy link

is anybody still facing the issue? Because I am still facing the same problem in v3.15.x and v3.17.x and my code is similar to what is described in this issue.

@DavideD
Copy link
Contributor

DavideD commented Dec 10, 2024

It's possible that you've found an entity mapping that's causing the same exception.
That EmbeddableInitializerImpl should be a ReactiveEmbeddableInitializerImpl.

If you can provide a test case, I will have a look.

@oaklandcorp-jkaiser
Copy link

After upgrading an API to Quarkus v3.15.2 I'm still witnessing errors too. If time permits I'll try to get some reproducible code together to help if someone doesn't beat me to the punch first. Might be tough since it is not small project.

java.lang.ClassCastException: org.hibernate.sql.results.graph.embeddable.internal.EmbeddableInitializerImpl cannot be cast to org.hibernate.reactive.sql.results.graph.ReactiveInitializer
	at org.hibernate.reactive.sql.results.graph.entity.internal.ReactiveEntityDelayedFetchInitializer.forEachReactiveSubInitializer(ReactiveEntityDelayedFetchInitializer.java:218)
	at org.hibernate.reactive.sql.results.graph.ReactiveInitializer.reactiveResolveKey(ReactiveInitializer.java:36)
	at org.hibernate.reactive.sql.results.graph.ReactiveInitializer.reactiveResolveKey(ReactiveInitializer.java:41)
	at org.hibernate.reactive.sql.results.graph.entity.internal.ReactiveEntityInitializerImpl.lambda$reactiveResolveKeySubInitializers$12(ReactiveEntityInitializerImpl.java:724)
	at org.hibernate.reactive.util.impl.CompletionStages.lambda$loop$2(CompletionStages.java:175)
	at org.hibernate.reactive.util.impl.CompletionStages.lambda$loop$7(CompletionStages.java:410)
	at org.hibernate.reactive.util.impl.CompletionStages$ArrayLoop.next(CompletionStages.java:484)
	at org.hibernate.reactive.util.async.impl.AsyncTrampoline.lambda$asyncWhile$1(AsyncTrampoline.java:215)
	at org.hibernate.reactive.util.async.impl.AsyncTrampoline$TrampolineInternal.unroll(AsyncTrampoline.java:121)
	at org.hibernate.reactive.util.async.impl.AsyncTrampoline$TrampolineInternal.trampoline(AsyncTrampoline.java:102)
	at org.hibernate.reactive.util.async.impl.AsyncTrampoline.asyncWhile(AsyncTrampoline.java:197)
	at org.hibernate.reactive.util.async.impl.AsyncTrampoline.asyncWhile(AsyncTrampoline.java:215)
	at org.hibernate.reactive.util.impl.CompletionStages.loop(CompletionStages.java:411)
	at org.hibernate.reactive.util.impl.CompletionStages.loop(CompletionStages.java:382)
	at org.hibernate.reactive.util.impl.CompletionStages.loop(CompletionStages.java:175)
	at org.hibernate.reactive.sql.results.graph.entity.internal.ReactiveEntityInitializerImpl.reactiveResolveKeySubInitializers(ReactiveEntityInitializerImpl.java:719)
	at org.hibernate.reactive.sql.results.graph.entity.internal.ReactiveEntityInitializerImpl.lambda$reactiveResolveKey$9(ReactiveEntityInitializerImpl.java:650)
	at [email protected]/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1187)
	at [email protected]/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2309)
	at [email protected]/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:144)
	at org.hibernate.reactive.sql.results.graph.entity.internal.ReactiveEntityInitializerImpl.lambda$reactiveResolveKey$10(ReactiveEntityInitializerImpl.java:632)
	at [email protected]/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1187)
	at [email protected]/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2309)
	at [email protected]/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:144)
	at org.hibernate.reactive.sql.results.graph.entity.internal.ReactiveEntityInitializerImpl.reactiveResolveKey(ReactiveEntityInitializerImpl.java:626)
	at org.hibernate.reactive.sql.results.graph.entity.internal.ReactiveEntityInitializerImpl.reactiveResolveKey(ReactiveEntityInitializerImpl.java:605)
	at org.hibernate.reactive.sql.results.graph.entity.internal.ReactiveEntityInitializerImpl.reactiveResolveKey(ReactiveEntityInitializerImpl.java:56)
	at org.hibernate.reactive.sql.results.internal.ReactiveStandardRowReader.resolveKey(ReactiveStandardRowReader.java:383)
	at org.hibernate.reactive.sql.results.internal.ReactiveStandardRowReader.lambda$coordinateInitializers$28(ReactiveStandardRowReader.java:376)
	at org.hibernate.reactive.util.impl.CompletionStages.lambda$loop$7(CompletionStages.java:410)
	at org.hibernate.reactive.util.impl.CompletionStages$ArrayLoop.next(CompletionStages.java:484)
	at org.hibernate.reactive.util.async.impl.AsyncTrampoline.lambda$asyncWhile$1(AsyncTrampoline.java:215)
	at org.hibernate.reactive.util.async.impl.AsyncTrampoline$TrampolineInternal.unroll(AsyncTrampoline.java:121)
	at org.hibernate.reactive.util.async.impl.AsyncTrampoline$TrampolineInternal.trampoline(AsyncTrampoline.java:102)
	at org.hibernate.reactive.util.async.impl.AsyncTrampoline.asyncWhile(AsyncTrampoline.java:197)
	at org.hibernate.reactive.util.async.impl.AsyncTrampoline.asyncWhile(AsyncTrampoline.java:215)
	at org.hibernate.reactive.util.impl.CompletionStages.loop(CompletionStages.java:411)
	at org.hibernate.reactive.util.impl.CompletionStages.loop(CompletionStages.java:382)
	at org.hibernate.reactive.sql.results.internal.ReactiveStandardRowReader.coordinateInitializers(ReactiveStandardRowReader.java:376)
	at org.hibernate.reactive.sql.results.internal.ReactiveStandardRowReader.reactiveReadRow(ReactiveStandardRowReader.java:126)
	at org.hibernate.reactive.sql.results.spi.ReactiveListResultsConsumer.lambda$addToResultsSupplier$5(ReactiveListResultsConsumer.java:141)
	at org.hibernate.reactive.sql.results.spi.ReactiveListResultsConsumer.lambda$consume$1(ReactiveListResultsConsumer.java:96)
	at [email protected]/java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:1150)
	at [email protected]/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
	at [email protected]/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2147)
	at io.vertx.core.Future.lambda$toCompletionStage$3(Future.java:601)
	at io.vertx.core.impl.future.FutureImpl$4.onSuccess(FutureImpl.java:176)
	at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:66)
	at io.vertx.core.impl.future.FutureImpl.tryComplete(FutureImpl.java:259)
	at io.vertx.sqlclient.impl.QueryResultBuilder.tryComplete(QueryResultBuilder.java:88)
	at io.vertx.sqlclient.impl.QueryResultBuilder.tryComplete(QueryResultBuilder.java:32)
	at io.vertx.core.Promise.complete(Promise.java:66)
	at io.vertx.core.Promise.handle(Promise.java:51)
	at io.vertx.core.Promise.handle(Promise.java:29)
	at io.vertx.core.impl.future.FutureImpl$4.onSuccess(FutureImpl.java:176)
	at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:66)
	at io.vertx.core.impl.future.FutureImpl.tryComplete(FutureImpl.java:259)
	at io.vertx.core.impl.future.PromiseImpl.onSuccess(PromiseImpl.java:49)
	at io.vertx.core.impl.future.PromiseImpl.handle(PromiseImpl.java:41)
	at io.vertx.sqlclient.impl.TransactionImpl.lambda$wrap$0(TransactionImpl.java:72)
	at io.vertx.core.impl.future.FutureImpl$4.onSuccess(FutureImpl.java:176)
	at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:66)
	at io.vertx.core.impl.future.FutureImpl.tryComplete(FutureImpl.java:259)
	at io.vertx.core.impl.future.Transformation$1.onSuccess(Transformation.java:61)
	at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:66)
	at io.vertx.core.impl.future.SucceededFuture.addListener(SucceededFuture.java:88)
	at io.vertx.core.impl.future.Transformation.onSuccess(Transformation.java:42)
	at io.vertx.core.impl.future.FutureBase.lambda$emitSuccess$0(FutureBase.java:60)
	at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:173)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:166)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:994)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at [email protected]/java.lang.Thread.run(Thread.java:833)
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:775)
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:203)

@DavideD
Copy link
Contributor

DavideD commented Dec 12, 2024

If you want some help with this issue, copying and pasting the stacktrace is not enough.
We need a test case to reproduce the error. Or, at the very least, an example of the entities you are using.

In Hibernate Reactive, we have this test case for embeddables: https://github.com/hibernate/hibernate-reactive/blob/aa5dd855a296bb28fcae6fc4d0593bac98287a28/hibernate-reactive-core/src/test/java/org/hibernate/reactive/EmbeddedIdTest.java#L27

What are you doing differently?

@oaklandcorp-jkaiser
Copy link

I understand. Unfortunately trying to reproduce the issue with as little code as possible and without any proprietary code is not a small task for a large project. I just wanted to share some technical information in case that helped limit things down while keeping the conversation going about there probably being a related problem still lingering. I'll do what I can to help contribute more information if time permits.

The project I'm trying to upgrade has automated Quarkus integration tests that should invoke the erroring code against a mock database; those pass fine. But a native build of the project running in the context of a larger system fails that same code path. It could just be that my integration test isn't a full representation of what is happening on a real system but my gut tells me something about the project running native has an impact on this error occurring... but this is all spitballing until I have the time to dig in for more details.

DavideD added a commit to DavideD/quarkus-quickstarts that referenced this issue Dec 13, 2024
@DavideD
Copy link
Contributor

DavideD commented Dec 13, 2024

I've adapted one of the quickstarts so that it uses an entity with an embedded id: DavideD/quarkus-quickstarts@d32cffe

I've tested it manually and it seems to work fine in native and non native mode.

Not sure how many entities you are dealing with, but this error happens on entities with an embedded id. So, it shouldn't be too hard to update it to at least try a mapping similar to the one you have. I don't think this errors is caused by the amount of fields, most likely you are fetching a collections of entities having an embedded id as a result of some query.

By the way, it shouldn't matter, but it might be helpful to know which database you are using.

@oaklandcorp-jkaiser
Copy link

Quick update here this morning. I've now been able to reproduce the Hibernate error in an integration test. It isn't native specific; the native path I was able to test quickly yesterday just had slightly more data on the record that wasn't included in the simpler JVM path. The ...fetching a collections of entities having an embedded id... hint was key to tracking down the difference. Thanks for that!

This API is quite dense: lots of entities, lots of fields per entity, and lots of nested relationships. It can just be slow to get to the heart of the matter in a project like this especially when maintenance isn't a top priority. I'm sure you can understand.

This API seems to return entities that share a parent class that has an embedded ID. Some entities have nested collections of other entities with the same parent class. I think that matches the description above.

I'm going to try and reproduce this setup by forking the quick start as you had. Hopefully that comes together quickly and I'll have something actually useful for you to look into.

@DavideD
Copy link
Contributor

DavideD commented Dec 13, 2024

Thanks for feedback and for looking into this.

@CarlosPanarello
Copy link
Contributor

It's possible that you've found an entity mapping that's causing the same exception. That EmbeddableInitializerImpl should be a ReactiveEmbeddableInitializerImpl.

If you can provide a test case, I will have a look.

I`m having the same problem, how can i force to use the reactive implementation instead normal one (EmbeddableInitializerImpl)?

@DavideD
Copy link
Contributor

DavideD commented Dec 16, 2024

Could you provide a test case? Or at least gives some details about your use case?

@CarlosPanarello
Copy link
Contributor

Could you provide a test case? Or at least gives some details about your use case?

I will, i`m doing this right now.

@DavideD
Copy link
Contributor

DavideD commented Dec 16, 2024

Great, thanks

@oaklandcorp-jkaiser
Copy link

@DavideD: I think I've got an error reproducible when you have the time to dig into it. I forked the quickstart repo at v3.15.2 and added a single commit that reworks the hibernate-reactive-quickstart enough to see the same type of exception I noted in a real API. Just run the testListAllFlowers test case to see the exception.

oaklandcorp-jkaiser/quarkus-quickstarts@16d59a6

@oaklandcorp-jkaiser
Copy link

Would it make sense to reopen this issue yet? If you all need more time to verify the linked case is indeed highlighting a bug that is fine. Just wanted to make sure this discussion didn't get lost over the holidays.

@yrodiere
Copy link
Member

yrodiere commented Jan 8, 2025

Would it make sense to reopen this issue yet? If you all need more time to verify the linked case is indeed highlighting a bug that is fine. Just wanted to make sure this discussion didn't get lost over the holidays.

If you're worried this will get lost, I'd suggest opening a dedicated issue, preferably at https://github.com/hibernate/hibernate-reactive/ , linking to this conversation and the reproducer.

@DavideD
Copy link
Contributor

DavideD commented Jan 8, 2025

I'm having a look now

@DavideD
Copy link
Contributor

DavideD commented Jan 8, 2025

I've adapted the test case for Hibernate Reactive and created the following issue: hibernate/hibernate-reactive#2060

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-reactive Hibernate Reactive kind/bug Something isn't working
Projects
None yet
9 participants