quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.73k stars 2.67k forks source link

quarkus-hibernate-reactive-rest-data-panache + reactive pgsql client: JSON-B (de)serialization fails for (Local|Offset)DateTime #28877

Closed karstengresch closed 1 year ago

karstengresch commented 1 year ago

Describe the bug

I want to implement basic CRUD for LocalDateTime/OffsetDateTime members, but fail with create/insert/POST.

A reproducer project has been created here: https://github.com/karstengresch/jsonbdatereproducer.git

Expected behavior

The POST method should be executed, a new record should have been inserted into the DB and the method should HTTP 200.

Actual behavior

Exceptions when calling the POST endpoint:

LocalDateTime

2022-10-27 12:03:26,491 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (vert.x-eventloop-thread-3) HTTP Request to /example failed, error id: b6e2928a-f9de-40bc-9180-0920df35f1e0-1: java.lang.IllegalStateException: io.vertx.core.impl.NoStackTraceThrowable: Parameter at position[0] with class = [java.time.LocalDateTime] and value = [2022-03-10T12:15:50] can not be coerced to the expected class = [java.time.OffsetDateTime] for encoding.
        at org.bydoing.ExampleEntity.lambda$createExampleEntity$0(ExampleEntity.java:49)
        at io.smallrye.context.impl.wrappers.SlowContextualFunction.apply(SlowContextualFunction.java:21)
        at io.smallrye.mutiny.operators.uni.UniOnFailureTransform$UniOnFailureTransformProcessor.onFailure(UniOnFailureTransform.java:54)
        at io.smallrye.mutiny.operators.uni.UniFailOnTimeout$UniFailOnTimeoutProcessor.onFailure(UniFailOnTimeout.java:80)
        at io.smallrye.mutiny.operators.uni.UniOperatorProcessor.onFailure(UniOperatorProcessor.java:54)
        at io.smallrye.mutiny.operators.uni.UniOperatorProcessor.onFailure(UniOperatorProcessor.java:54)
        at io.smallrye.mutiny.operators.uni.UniOnItemOrFailureConsume$UniOnItemOrFailureConsumeProcessor.onFailure(UniOnItemOrFailureConsume.java:46)
        at io.smallrye.mutiny.operators.uni.UniOperatorProcessor.onFailure(UniOperatorProcessor.java:54)
        at io.smallrye.mutiny.operators.uni.UniOperatorProcessor.onFailure(UniOperatorProcessor.java:54)
        at io.smallrye.mutiny.operators.uni.UniOperatorProcessor.onFailure(UniOperatorProcessor.java:54)
        at io.smallrye.mutiny.operators.uni.UniOnCancellationCall$UniOnCancellationCallProcessor.onFailure(UniOnCancellationCall.java:59)
        at io.smallrye.mutiny.operators.uni.UniOnFailureFlatMap$UniOnFailureFlatMapProcessor.onFailure(UniOnFailureFlatMap.java:62)
        at io.smallrye.mutiny.operators.uni.UniOnFailureTransform$UniOnFailureTransformProcessor.onFailure(UniOnFailureTransform.java:64)
        at io.smallr

OffsetDateTime

2022-10-27 11:58:27,843 ERROR [org.jbo.res.rea.com.cor.AbstractResteasyReactiveContext] (vert.x-eventloop-thread-3) Request failed: javax.json.bind.JsonbException: Unable to deserialize property 'exampledate' because of: Error parsing class java.time.OffsetDateTime from value: 2022-03-10T12:15:50-04:00. Check your @JsonbDateFormat has all time units for class java.time.OffsetDateTime type, or consider using org.eclipse.yasson.YassonConfig#ZERO_TIME_PARSE_DEFAULTING.
        at org.eclipse.yasson.internal.serializer.AbstractContainerDeserializer.deserializeInternal(AbstractContainerDeserializer.java:100)
        at org.eclipse.yasson.internal.serializer.AbstractContainerDeserializer.deserialize(AbstractContainerDeserializer.java:64)
        at org.eclipse.yasson.internal.Unmarshaller.deserializeItem(Unmarshaller.java:62)
        at org.eclipse.yasson.internal.Unmarshaller.deserialize(Unmarshaller.java:51)
        at org.eclipse.yasson.internal.JsonBinding.deserialize(JsonBinding.java:59)
        at org.eclipse.yasson.internal.JsonBinding.fromJson(JsonBinding.java:99)
        at org.jboss.resteasy.reactive.server.jsonb.JsonbMessageBodyReader.doReadFrom(JsonbMessageBodyReader.java:57)
        at org.jboss.resteasy.reactive.server.jsonb.JsonbMessageBodyReader.readFrom(JsonbMessageBodyReader.java:39)
        at org.jboss.resteasy.reactive.server.handlers.RequestDeserializeHandler.readFrom(RequestDeserializeHandler.java:122)
        at org.jboss.resteasy.reactive.server.handlers.RequestDeserializeHandler.handle(RequestDeserializeHandler.java:81)
        at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:108)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:145)
        at org.jboss.resteasy.reactive.server.vertx.VertxResteasyReactiveRequestContext$1$1.handle(VertxResteasyReactiveRequestContext.java:78)
        at org.jboss.resteasy.reactive.server.vertx.VertxResteasyReactiveRequestContext$1$1.handle(VertxResteasyReactiveRequestContext.java:75)
        at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:264)
        at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:246)
        at io.vertx.core.impl.EventLoopContext.lambda$runOnContext$0(EventLoopContext.java:43)
        at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:566)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: javax.json.bind.JsonbException: Error parsing class java.time.OffsetDateTime from value: 2022-03-10T12:15:50-04:00. Check your @JsonbDateFormat has all time units for class java.time.OffsetDateTime type, or consider using org.eclipse.yasson.YassonConfig#ZERO_TIME_PARSE_DEFAULTING.
        at org.eclipse.yasson.internal.serializer.AbstractDateTimeDeserializer.parseWithFormatterInternal(AbstractDateTimeDeserializer.java:135)
        at org.eclipse.yasson.internal.serializer.AbstractDateTimeDeserializer.deserialize(AbstractDateTimeDeserializer.java:59)
        at org.eclipse.yasson.internal.serializer.AbstractValueTypeDeserializer.deserialize(AbstractValueTypeDeserializer.java:64)
        at org.eclipse.yasson.internal.serializer.ObjectDeserializer.deserializeNext(ObjectDeserializer.java:183)
        at org.eclipse.yasson.internal.serializer.AbstractContainerDeserializer.deserializeInternal(AbstractContainerDeserializer.java:94)
        ... 24 more
Caused by: java.time.format.DateTimeParseException: Text '2022-03-10T12:15:50-04:00' could not be parsed, unparsed text found at index 19
        at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2055)
        at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1954)
        at java.base/java.time.OffsetDateTime.parse(OffsetDateTime.java:404)
        at org.eclipse.yasson.internal.serializer.OffsetDateTimeTypeDeserializer.parseWithFormatter(OffsetDateTimeTypeDeserializer.java:58)
        at org.eclipse.yasson.internal.serializer.OffsetDateTimeTypeDeserializer.parseWithFormatter(OffsetDateTimeTypeDeserializer.java:28)
        at org.eclipse.yasson.internal.serializer.AbstractDateTimeDeserializer.parseWithFormatterInternal(AbstractDateTimeDeserializer.java:133)
        ... 28 more

How to Reproduce?

  1. Created a project via https://code.quarkus.io/

  2. Followed the guides at https://quarkus.io/guides/hibernate-reactive-panache and https://quarkus.io/guides/reactive-sql-clients (but using the Panache approach, not the reactive clients, i.e. no named query for inserts).

    Not following the CRUD resource approach (https://quarkus.io/guides/rest-data-panache) due to missing pgsql support.

  3. Final pom.xml (NB Lombok added, see full file in repo!):

    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy-reactive-jsonb</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy-reactive-jackson</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy-reactive</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-arc</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-hibernate-reactive-rest-data-panache</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-reactive-pg-client</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-smallrye-openapi</artifactId>
    </dependency>
  4. DB manually started (as dev services DB instantiation didn't work) w/

podman run -it --rm=true --name exampledb -e POSTGRES_USER=exampledb -e POSTGRES_PASSWORD=exampledb -e POSTGRES_DB=exampledb -p 5432:5432 postgres:14.5

  1. Run
curl -X 'GET' \
  'http://localhost:8080/example' \
  -H 'accept: application/json'

to get

[
  {
    "exampledate": "2023-08-24T14:00:00",
    "id": 1
  },
  {
    "exampledate": "2023-09-25T15:00:00",
    "id": 2
  },
  {
    "exampledate": "2023-10-26T16:00:00",
    "id": 3
  }
]
  1. Run
curl -X 'POST' \
  'http://localhost:8080/example' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "id": 0,
  "exampledate": "2022-03-10T12:15:50"
}'

(omitting the "id" parameter is optional)

and the error is

2022-10-27 11:58:27,843 ERROR [org.jbo.res.rea.com.cor.AbstractResteasyReactiveContext] (vert.x-eventloop-thread-3) Request failed: javax.json.bind.JsonbException: Unable to deserialize property 'exampledate' because of: Error parsing class java.time.OffsetDateTime from value: 2022-03-10T12:15:50-04:00. Check your @JsonbDateFormat has all time units for class java.time.OffsetDateTime type, or consider using org.eclipse.yasson.YassonConfig#ZERO_TIME_PARSE_DEFAULTING.
        at org.eclipse.yasson.internal.serializer.AbstractContainerDeserializer.deserializeInternal(AbstractContainerDeserializer.java:100)
        at org.eclipse.yasson.internal.serializer.AbstractContainerDeserializer.deserialize(AbstractContainerDeserializer.java:64)
        at org.eclipse.yasson.internal.Unmarshaller.deserializeItem(Unmarshaller.java:62)
        at org.eclipse.yasson.internal.Unmarshaller.deserialize(Unmarshaller.java:51)
        at org.eclipse.yasson.internal.JsonBinding.deserialize(JsonBinding.java:59)
        at org.eclipse.yasson.internal.JsonBinding.fromJson(JsonBinding.java:99)
        at org.jboss.resteasy.reactive.server.jsonb.JsonbMessageBodyReader.doReadFrom(JsonbMessageBodyReader.java:57)
        at org.jboss.resteasy.reactive.server.jsonb.JsonbMessageBodyReader.readFrom(JsonbMessageBodyReader.java:39)
        at org.jboss.resteasy.reactive.server.handlers.RequestDeserializeHandler.readFrom(RequestDeserializeHandler.java:122)
        at org.jboss.resteasy.reactive.server.handlers.RequestDeserializeHandler.handle(RequestDeserializeHandler.java:81)
        at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:108)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:145)
        at org.jboss.resteasy.reactive.server.vertx.VertxResteasyReactiveRequestContext$1$1.handle(VertxResteasyReactiveRequestContext.java:78)
        at org.jboss.resteasy.reactive.server.vertx.VertxResteasyReactiveRequestContext$1$1.handle(VertxResteasyReactiveRequestContext.java:75)
        at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:264)
        at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:246)
        at io.vertx.core.impl.EventLoopContext.lambda$runOnContext$0(EventLoopContext.java:43)
        at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:566)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: javax.json.bind.JsonbException: Error parsing class java.time.OffsetDateTime from value: 2022-03-10T12:15:50-04:00. Check your @JsonbDateFormat has all time units for class java.time.OffsetDateTime type, or consider using org.eclipse.yasson.YassonConfig#ZERO_TIME_PARSE_DEFAULTING.
        at org.eclipse.yasson.internal.serializer.AbstractDateTimeDeserializer.parseWithFormatterInternal(AbstractDateTimeDeserializer.java:135)
        at org.eclipse.yasson.internal.serializer.AbstractDateTimeDeserializer.deserialize(AbstractDateTimeDeserializer.java:59)
        at org.eclipse.yasson.internal.serializer.AbstractValueTypeDeserializer.deserialize(AbstractValueTypeDeserializer.java:64)
        at org.eclipse.yasson.internal.serializer.ObjectDeserializer.deserializeNext(ObjectDeserializer.java:183)
        at org.eclipse.yasson.internal.serializer.AbstractContainerDeserializer.deserializeInternal(AbstractContainerDeserializer.java:94)
        ... 24 more
Caused by: java.time.format.DateTimeParseException: Text '2022-03-10T12:15:50-04:00' could not be parsed, unparsed text found at index 19
        at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2055)
        at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1954)
        at java.base/java.time.OffsetDateTime.parse(OffsetDateTime.java:404)
        at org.eclipse.yasson.internal.serializer.OffsetDateTimeTypeDeserializer.parseWithFormatter(OffsetDateTimeTypeDeserializer.java:58)
        at org.eclipse.yasson.internal.serializer.OffsetDateTimeTypeDeserializer.parseWithFormatter(OffsetDateTimeTypeDeserializer.java:28)
        at org.eclipse.yasson.internal.serializer.AbstractDateTimeDeserializer.parseWithFormatterInternal(AbstractDateTimeDeserializer.java:133)
        ... 28 more
  1. Checkout the localdatetime branch and run (5, optional, and) 6. again and you'll get this error
2022-10-27 12:03:26,491 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (vert.x-eventloop-thread-3) HTTP Request to /example failed, error id: b6e2928a-f9de-40bc-9180-0920df35f1e0-1: java.lang.IllegalStateException: io.vertx.core.impl.NoStackTraceThrowable: Parameter at position[0] with class = [java.time.LocalDateTime] and value = [2022-03-10T12:15:50] can not be coerced to the expected class = [java.time.OffsetDateTime] for encoding.
        at org.bydoing.ExampleEntity.lambda$createExampleEntity$0(ExampleEntity.java:49)
        at io.smallrye.context.impl.wrappers.SlowContextualFunction.apply(SlowContextualFunction.java:21)
        at io.smallrye.mutiny.operators.uni.UniOnFailureTransform$UniOnFailureTransformProcessor.onFailure(UniOnFailureTransform.java:54)
        at io.smallrye.mutiny.operators.uni.UniFailOnTimeout$UniFailOnTimeoutProcessor.onFailure(UniFailOnTimeout.java:80)
        at io.smallrye.mutiny.operators.uni.UniOperatorProcessor.onFailure(UniOperatorProcessor.java:54)
        at io.smallrye.mutiny.operators.uni.UniOperatorProcessor.onFailure(UniOperatorProcessor.java:54)
        at io.smallrye.mutiny.operators.uni.UniOnItemOrFailureConsume$UniOnItemOrFailureConsumeProcessor.onFailure(UniOnItemOrFailureConsume.java:46)
        at io.smallrye.mutiny.operators.uni.UniOperatorProcessor.onFailure(UniOperatorProcessor.java:54)
        at io.smallrye.mutiny.operators.uni.UniOperatorProcessor.onFailure(UniOperatorProcessor.java:54)
        at io.smallrye.mutiny.operators.uni.UniOperatorProcessor.onFailure(UniOperatorProcessor.java:54)
        at io.smallrye.mutiny.operators.uni.UniOnCancellationCall$UniOnCancellationCallProcessor.onFailure(UniOnCancellationCall.java:59)
        at io.smallrye.mutiny.operators.uni.UniOnFailureFlatMap$UniOnFailureFlatMapProcessor.onFailure(UniOnFailureFlatMap.java:62)
        at io.smallrye.mutiny.operators.uni.UniOnFailureTransform$UniOnFailureTransformProcessor.onFailure(UniOnFailureTransform.java:64)
        at io.smallr
  1. Checkout the nolombok branch if you wish to confirm that the problem exists w/o Lombok dependency and annotations.

Output of uname -a or ver

Darwin KGRHMBP01 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64 x86_64

Output of java -version

openjdk 17.0.4.1 2022-08-12 OpenJDK Runtime Environment Temurin-17.0.4.1+1 (build 17.0.4.1+1) OpenJDK 64-Bit Server VM Temurin-17.0.4.1+1 (build 17.0.4.1+1, mixed mode, sharing)

GraalVM version (if different from Java)

N/A, no native compile, only JVM mode

Quarkus version or git rev

2.13.2.Final

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

Maven home: ~/.m2/wrapper/dists/apache-maven-3.8.1-bin/2l5mhf2pq2clrde7f7qp1rdt5m/apache-maven-3.8.1 Java version: 17.0.4.1, vendor: Eclipse Adoptium, runtime: ~/.sdkman/candidates/java/17.0.4.1-tem Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "12.4", arch: "x86_64", family: "mac"

Additional information

Used io.quarkus/999-SNAPSHOT

Maybe I just missed (i.e. misunderstood) something elementary (e.g. wrong formatter String or else) and this is not a bug, then please see this contribution to

quarkus-bot[bot] commented 1 year ago

/cc @DavideD, @FroMage, @Sanne, @Sgitario, @gavinking, @loicmathieu

Sgitario commented 1 year ago

I think this issue is duplicated with https://github.com/quarkusio/quarkus/issues/10768. This is a very good explanation of the issue by @DavideD https://github.com/quarkusio/quarkus/issues/10768#issuecomment-1023581785 The workaround I used to make your reproducer work is the one described in https://github.com/quarkusio/quarkus/issues/10768#issuecomment-848942893, plus adding the offset as part of the formatted:

@Type(type = "org.bydoing.TimestampWithTimezone")
    @Column(name = "exampledate", nullable = false, updatable = false, columnDefinition = "timestamp with time zone not null")
    @JsonbDateFormat(value="yyyy-MM-dd'T'HH:mm:ss.SSSXXX") // see new formatter
    public OffsetDateTime exampledate;

Alternatively, you can instruct JsonB to default offset to zero as said in the exception:

Caused by: javax.json.bind.JsonbException: Error parsing class java.time.OffsetDateTime from value: 2022-03-10T12:15:50-04:00. Check your @JsonbDateFormat has all time units for class java.time.OffsetDateTime type, or consider using org.eclipse.yasson.YassonConfig#ZERO_TIME_PARSE_DEFAULTING.
        at org.eclipse.yasson.internal.serializer.AbstractDateTimeDeserializer.parseWithFormatterInternal(AbstractDateTimeDeserializer.java:135)
        at org.eclipse.yasson.internal.serializer.AbstractDateTimeDeserializer.deserialize(AbstractDateTimeDeserializer.java:59)
        at org.eclipse.yasson.internal.serializer.AbstractValueTypeDeserializer.deserialize(AbstractValueTypeDeserializer.java:64)
        at org.eclipse.yasson.internal.serializer.ObjectDeserializer.deserializeNext(ObjectDeserializer.java:183)
        at org.eclipse.yasson.internal.serializer.AbstractContainerDeserializer.deserializeInternal(AbstractContainerDeserializer.java:94)
        ... 24 more

See how to configure JSON B here: https://quarkus.io/guides/rest-json#json-b

DavideD commented 1 year ago

I think the problem is that the pattern and the date you've specified don't contain an offset. If you remove the annotation @JsonDateFormat and add Z at the end of the date, it should be able to parse the date correctly:

curl -X 'POST' \
  'http://localhost:8080/example' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "id": 0,
  "exampledate": "2022-03-10T12:15:50Z"
}'

But you will face another issue. Currently there is a problem about using timestamp with time zone with Postgres and Hibernate Reactive.

This happens because postgres doesn't actually save the time zone and convert everything to UTC:

For timestamp with time zone, the internally stored value is always in UTC (Universal Coordinated Time, traditionally known as Greenwich Mean Time, GMT). An input value that has an explicit time zone specified is converted to UTC using the appropriate offset for that time zone. If no time zone is stated in the input string, then it is assumed to be in the time zone indicated by the system's TimeZone parameter, and is converted to UTC using the offset for the timezone zone.

At the moment, if you want to handle timezones with Hibernate Reactive and Postgres, you might need to store the offset in a separate field.

I also don't think it's a good idea to drop-and-create tables in several different places. In the properties, you already specify the property quarkus.hibernate-orm.database.generation=drop-and-create. So, you don't have to recreate the table in the import.sql or in the test.

I've created a git patch containing the changes I've applied to make the example work: https://gist.github.com/DavideD/9e383b1177c6ddb0624812af43ac557b

This will map the column exampledate as timestamp (and not timestampz)

karstengresch commented 1 year ago

Thanks @Sgitario for the explanation and even more @DavideD for the even deeper explanation and the patch!

That was extremely fast, much appreciated. I'll test this out (b.t.w. I had already tested all sorts of format Strings as well as all sorts of HTTP-body-param values) and give you some feedback on this!

karstengresch commented 1 year ago

@DavideD - thanks very much, I can confirm it's working with your example.

For the later interested reader: working solution in branch https://github.com/karstengresch/jsonbdatereproducer/tree/solution

Notes to that:

Hope this is useful for somebody stumbling upon this.

DavideD commented 1 year ago

I'm closing this issue, but if you have other questions don't hesitate to ask.

DavideD commented 1 year ago

By the way, in case you don't know, if you add the prefix %prod to some properties in the application.properties, Quarkus will automatically starts a docker container with the correct database to run the tests.

These are the changes I've done so that mvn quarkus:dev would also start the db:

quarkus.datasource.db-kind=postgresql
%prod.quarkus.datasource.username=exampledb
%prod.quarkus.datasource.password=exampledb
# podman run -it --rm=true --name exampledb -e POSTGRES_USER=exampledb -e POSTGRES_PASSWORD=exampledb -e POSTGRES_DB=exampledb -p 5432:5432 postgres:14.5
%prod.quarkus.datasource.reactive.url=vertx-reactive:postgresql://localhost:5432/exampledb
quarkus.datasource.reactive.max-size=20
exampledb.schema.create=true
quarkus.hibernate-orm.database.generation=drop-and-create                                                          
karstengresch commented 1 year ago

Thanks very much again, @DavideD !

I incorporated this into the working solution, but commented it out:

Working on macOS and using Podman. This doesn't seem to be supported, https://quarkus.io/blog/quarkus-devservices-testcontainers-podman/

Following the instructions from https://quarkus.io/guides/podman incl. alias docker='podman' didn't work. I think I somewhere read there was some quarkus property where podman could be specified but this was IIRC just for image creation, not dev services/tescontainers.

I for sure know my next RH notebook will be Linux based (as most of my home machines are) :D