Enable DataNucleus to deal with JSONB
columns
#1074
Labels
component/api-server
enhancement
New feature or request
p3
Nice-to-have features
size/M
Medium effort
PostgreSQL's
JSONB
columns are more efficient to store, faster to query, and can be indexed.DataNucleus does not support
JSONB
type per default.We can map Java objects to JSON strings using custom
AttributeConverter
s, but when inserting the resulting strings, Postgres yields a type error, e.g.:With raw SQL, this could be addressed using explicit casting, like this:
But with DataNucleus we don't get to make this customization.
Transmitting
JSONB
through raw JDBC can be achieved usingPGobject
:To get this level of control with DataNucleus, it seems like we have to build a DataNucleus extension, which provides a
ColumnMapping
, as per https://www.datanucleus.org/products/accessplatform/extensions/extensions.html#rdbms_datastore_mappingI made some progress using the extension way, but got stuck when trying to also make it work with H2, which is still being used in some tests.
Fields annotated with
@Column
must then include thesqlType = "JSONB"
qualifier for theColumnMapper
to be picked up:This works fine when using Postgres, but fails in tests where DataNucleus auto-generates the schema for an in-memory H2 database:
The root cause being that H2 doesn't have a
JSONB
type.The text was updated successfully, but these errors were encountered: