Skip to content

Instantly share code, notes, and snippets.

@madz0
Created October 9, 2019 18:21
Show Gist options
  • Save madz0/fad126864e234e93d7294809d7372a0d to your computer and use it in GitHub Desktop.
Save madz0/fad126864e234e93d7294809d7372a0d to your computer and use it in GitHub Desktop.
jsonb work around for H2 database

Creat a package-info file in the models package and put the following contents in there:

@org.hibernate.annotations.TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
package com.ourproject.model;

import com.vladmihalcea.hibernate.type.json.JsonBinaryType;

I used JsonBinaryType in hibernate-types-52 library.

Then in the entity class, I removed columnDefinition="jsonb" from the @Column and only used @Type(type = "jsonb")

This way, for the product, hibernate would map column to jsonb type. Then in the test folder inside the same package I added package-info with this contents:

@org.hibernate.annotations.TypeDef(name = "jsonb", typeClass = TextType.class)
package com.ourproject.model;

import org.hibernate.type.TextType;

Now when we run maven test hibernate generates varchar(2147483647) column type for the jsonb type and it solved.

@ClintEsteMadera
Copy link

this worked like a charm to me, thanks a lot!

@madz0
Copy link
Author

madz0 commented Sep 30, 2020

Glad it helped mate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment