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

NullPointerException for jsonb Postgres column #685

Open
heck-gd opened this issue Apr 19, 2024 · 0 comments
Open

NullPointerException for jsonb Postgres column #685

heck-gd opened this issue Apr 19, 2024 · 0 comments

Comments

@heck-gd
Copy link

heck-gd commented Apr 19, 2024

We're currently migrating a project to hibernate6 and ran into an issue. Our database server is PostgreSQL and we're using the io.hypersistence:hypersistence-utils-hibernate-63 package to get json/jsonb column support in Hibernate.

A simplified example looks like this:

import io.hypersistence.utils.hibernate.type.json.JsonBinaryType;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.Type;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;

public class TheData {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotNull
    @Type(JsonBinaryType.class)
    @Column(columnDefinition = "jsonb")
    @ColumnDefault("{}")
    private String info = "{}";
}

When running diffChangelog, this results in:

Caused by: java.lang.NullPointerException: Cannot invoke "liquibase.datatype.LiquibaseDataType.getName()" because "liquibaseDataType" is null
	at liquibase.util.SqlUtil.parseValue(SqlUtil.java:244)
	at liquibase.ext.hibernate.snapshot.ColumnSnapshotGenerator.snapshotColumn(ColumnSnapshotGenerator.java:130)
	at liquibase.ext.hibernate.snapshot.ColumnSnapshotGenerator.addTo(ColumnSnapshotGenerator.java:78)
	at liquibase.ext.hibernate.snapshot.HibernateSnapshotGenerator.snapshot(HibernateSnapshotGenerator.java:82)
	at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:49)
	at liquibase.snapshot.DatabaseSnapshot.include(DatabaseSnapshot.java:313)
	at liquibase.snapshot.DatabaseSnapshot.replaceObject(DatabaseSnapshot.java:456)
	at liquibase.snapshot.DatabaseSnapshot.replaceObject(DatabaseSnapshot.java:478)
	at liquibase.snapshot.DatabaseSnapshot.includeNestedObjects(DatabaseSnapshot.java:369)
	at liquibase.snapshot.DatabaseSnapshot.include(DatabaseSnapshot.java:332)
	at liquibase.snapshot.DatabaseSnapshot.init(DatabaseSnapshot.java:106)
	at liquibase.snapshot.DatabaseSnapshot.<init>(DatabaseSnapshot.java:59)
	at liquibase.snapshot.JdbcDatabaseSnapshot.<init>(JdbcDatabaseSnapshot.java:38)
	at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:214)
	at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:187)
	at liquibase.command.core.DiffCommandStep.generateDatabaseShapshot(DiffCommandStep.java:205)
	at liquibase.command.core.DiffCommandStep.createReferenceSnapshot(DiffCommandStep.java:192)
	at liquibase.command.core.DiffCommandStep.createDiffResult(DiffCommandStep.java:113)
	at liquibase.command.core.DiffCommandStep.run(DiffCommandStep.java:89)
	at liquibase.command.CommandScope.execute(CommandScope.java:219)
	... 18 more

It logs [liquibase.ext] Found column info jsonb, but the parseType is an object where all fields are null, causing the exception.

hibernateColumn contains a value of type BasicValue which in turn has a resolution that contains the JsonBinaryType stuff, but Liquibase doesn't seem to pick up on it. The typeName field is not going to be set for such values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant