Skip to content

Persisting to Postgres jsonb column broken #36730

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

Closed
vanuatoo opened this issue Oct 26, 2023 · 6 comments
Closed

Persisting to Postgres jsonb column broken #36730

vanuatoo opened this issue Oct 26, 2023 · 6 comments
Labels
kind/bug Something isn't working

Comments

@vanuatoo
Copy link

vanuatoo commented Oct 26, 2023

Describe the bug

In order to persist to Postgresql table with the column type of jsonb, I have an JPA Entity defined as
....
@column(name = "payload")
@JdbcTypeCode(SqlTypes.JSON)
public JsonObject eventPayload;
......

I use jakarta.json.JsonObject here.

Expected behavior

When I save the arbitrary payload constructed from the code
Json.createObjectBuilder()
.add("id", 1)
.add("name", "Quarkus")
.build();

I expect that it is stored properly in the database, like
{"id": 1, "name": "Quarkus"}

Actual behavior

The payload is stored like
{"id": {"valueType": "NUMBER"}, "name": {"valueType": "STRING"}}

How to Reproduce?

  1. Create a Quarkus project
  2. Create JPA Entity with the field to hold JsonObject
  3. Create Panache Repo and store the JPA Entity in Postgresql database

Output of uname -a or ver

Darwin EPGETBIW0449 23.0.0 Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:43 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T6000 arm64

Output of java -version

openjdk version "21.0.1" 2023-10-17 LTS OpenJDK Runtime Environment Temurin-21.0.1+12 (build 21.0.1+12-LTS) OpenJDK 64-Bit Server VM Temurin-21.0.1+12 (build 21.0.1+12-LTS, mixed mode)

Quarkus version or git rev

3.5.0

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

No response

Additional information

No response

@vanuatoo vanuatoo added the kind/bug Something isn't working label Oct 26, 2023
@vanuatoo
Copy link
Author

vanuatoo commented Oct 26, 2023

The code used to work with 3.2 version of the Quarkus on Java 17

@sfali16
Copy link

sfali16 commented Oct 31, 2023

Hi @vanuatoo,
I'm new to quarkus and trying to reproduce this bug to fix it - Can you point me to a standalone (full) example of code that you expect to work here ?

I started off with a quarkus quickstart for Hibernate ORM with Panache and Rest - https://github.com/quarkusio/quarkus-quickstarts/tree/main/hibernate-orm-rest-data-panache-quickstart - and have it creating a postgres database with entity, but I'm unable to get a working example of adding a jsonb column type (unsure if it's due to Hibernate or due to this bug)

Thanks !

@sfali16
Copy link

sfali16 commented Oct 31, 2023

Here's a draft PR for the quarkus quickstarts showing the commits I made with an example of how to use a JsonB - this works fine on postgres:
quarkusio/quarkus-quickstarts#1346

@sfali16
Copy link

sfali16 commented Nov 1, 2023

I used a Map<String, Object> and quarkus figured out how to persist that correctly.

@JdbcTypeCode(SqlTypes.JSON)
public Map<String, Object> jsonAddress;

When I tried to JsonObject it failed to find a serializer / deserializer for the class, so i would have had to provide a converter as in link, which didn't seem worth the effort when the Map works.
See https://thorben-janssen.com/persist-postgresqls-jsonb-data-type-hibernate/ for Hibernate 6 and Hibernate 5 mechanisms to use json column.

@vanuatoo Can you use the Map solution or provide a standalone example that reproduces the problem?

@vanuatoo
Copy link
Author

vanuatoo commented Nov 3, 2023

I used Map and it works fine.

@Ordiel
Copy link

Ordiel commented Oct 2, 2024

I would expect this to work with JsonObject itself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants