Cannot seem to persist new entities

I have started working on an example project to use Hibernate Reactive with Vert.x. I have gotten to the point where I can instantiate the Session and attempt to persist an entity object, but I keep getting the following error:

[INFO] java.util.concurrent.CompletionException: java.lang.NoSuchMethodError: 'io.vertx.sqlclient.Transaction io.vertx.sqlclient.SqlConnection.begin()'
[INFO]  at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:314)
[INFO]  at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:319)
[INFO]  at java.base/java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:1155)
[INFO]  at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
[INFO]  at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2137)
[INFO]  at org.hibernate.reactive.pool.impl.Handlers.lambda$toCompletionStage$0(Handlers.java:26)
[INFO]  at org.hibernate.reactive.pool.impl.SqlClientPool.lambda$null$0(SqlClientPool.java:77)

Example project can be found here: GitHub - InfoSec812/vertx-hibernate-reactive-experiment: An experiement to see how to integrate Hibernate Reactive with Vert.x

You can run it by executing: mvn clean compile vertx:run

You’ll be able to see the (generated) entity classes in src/gen/java after the generate-sources phase of the Maven build.

Hi, it looks like you’re using vert.x 4. The current release or HR requires the most recent version of Vert.x 3.

Whelp, that might explain it… I was wondering about that but I didn’t see anything in the guides which called it out. Thanks Gavin!

Support for 4 is coming very soon (we already have it working on a branch). We’re just waiting for Quarkus to upgrade before we do.

So, I tried again with Vert.x 3.9.6 and 3.8.5 and now I get a different error, but still an error.

It appears the Hibernate Reactive creates it’s own Vert.x context?

[INFO] WARNING: You're already on a Vert.x context, are you sure you want to create a new Vertx instance?
[INFO] java.lang.InstantiationError: io.vertx.sqlclient.SqlConnectOptions
[INFO]  at org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration.connectOptions(DefaultSqlClientPoolConfiguration.java:138)
[INFO]  at org.hibernate.reactive.pool.impl.DefaultSqlClientPool.createPools(DefaultSqlClientPool.java:104)
[INFO]  at org.hibernate.reactive.pool.impl.DefaultSqlClientPool.start(DefaultSqlClientPool.java:77)
[INFO]  at org.hibernate.service.internal.AbstractServiceRegistryImpl.startService(AbstractServiceRegistryImpl.java:344)
[INFO]  at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:249)
[INFO]  at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
[INFO]  at org.hibernate.reactive.provider.service.ReactiveGenerationTarget.prepare(ReactiveGenerationTarget.java:48)
[INFO]  at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:122)
[INFO]  at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:112)
[INFO]  at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:145)
[INFO]  at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:73)
[INFO]  at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:318)
[INFO]  at org.hibernate.reactive.session.impl.ReactiveSessionFactoryImpl.<init>(ReactiveSessionFactoryImpl.java:33)
[INFO]  at org.hibernate.reactive.provider.service.ReactiveSessionFactoryBuilder.build(ReactiveSessionFactoryBuilder.java:52)
[INFO]  at org.hibernate.reactive.provider.impl.ReactiveEntityManagerFactoryBuilder.build(ReactiveEntityManagerFactoryBuilder.java:59)
[INFO]  at org.hibernate.reactive.provider.ReactivePersistenceProvider.createEntityManagerFactory(ReactivePersistenceProvider.java:52)
[INFO]  at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
[INFO]  at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
[INFO]  at com.zanclus.vertx.MainVerticle.start(MainVerticle.java:22)
[INFO]  at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$9(DeploymentManager.java:556)
[INFO]  at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:369)
[INFO]  at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
[INFO]  at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
[INFO]  at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:510)
[INFO]  at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:518)
[INFO]  at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1044)
[INFO]  at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
[INFO]  at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
[INFO]  at java.base/java.lang.Thread.run(Thread.java:832)
[INFO] java.lang.NullPointerException: Cannot invoke "javax.persistence.EntityManagerFactory.unwrap(java.lang.Class)" because "this.emf" is null
[INFO]  at com.zanclus.vertx.MainVerticle.start(MainVerticle.java:28)
[INFO]  at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$9(DeploymentManager.java:556)
[INFO]  at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:369)
[INFO]  at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
[INFO]  at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
[INFO]  at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:510)
[INFO]  at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:518)
[INFO]  at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1044)
[INFO]  at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
[INFO]  at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
[INFO]  at java.base/java.lang.Thread.run(Thread.java:832)

I updated the reproducer on GitHub…

Hi, look, your project had multiple problems which prevented it from even compiling:

  1. Missing Todo entity.
  2. Vert.x 3.8.5 instead of the latest version 3.9.6.
  3. Older version of Hibernate instead of 5.4.29.
  4. Missing main() method to actually run Vert.x.
  5. Incorrect usage of Vert.x+Mutiny. You’re calling session.persist() to instantiate a Uni from within a void method and then just throwing away the Uni. So the reactive stream is never actually executed.

I deleted irrelevant gunk from the pom and added the missing code, and got as far as running schema export successfully and starting Vert.x. So the error you posted above was probably related to incompatible dependencies. (It’s always better to just delete unused crap from your pom when troubleshooting.)

FTR, the compatible versions of dependencies are listed here:

https://github.com/hibernate/hibernate-reactive#compatibility

OTOH, you really need to chat with the Vert.x/Mutiny guys to figure out the recommended way to adapt between Mutiny streams and Vert.x handlers. I have code to do that in HR, but it’s rather specialized to our purposes, and I don’t know the recommended way to do it in a generic Vert.x program. And above all: make sure you understand conceptually the programming model of reactive streams. You can’t just call session.persist() and expect something to happen. This is the #1 error everyone makes when they first use reactive streams, and it’s why I specifically called it out in the HR documentation. (If you read the docs you’ll find I have included quite a large number of warnings and tips.)

Thank you for your time.