4

I upgraded to Springboot 3.0 and in my hibernate entity class has something like:

    @Column(columnDefinition = "jsonb", nullable = false, updatable = true, name = "accounts") 
    @Type(type = "jsonb")
    private ArrayList<Account> accounts;

But I'm getting the exception 'Cannot resolve method 'type' since upgrading to Springboot 3.0 and moving to Jakarta persistence.

I need a replacement for com.vladmihalcea.hibernate.type.json.JsonBinaryType;

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
TrollBearPig
  • 496
  • 1
  • 7
  • 17

4 Answers4

6

I found the answer:

I had to use the lib:

<groupId>com.vladmihalcea</groupId> 
<artifactId>hibernate-types-60</artifactId> 

and in the entity:

    @Column(columnDefinition = "jsonb", nullable = false, updatable = true, name = "accounts") 
    @Type(JsonBinaryType.class)
    private ArrayList<Account> accounts;
TrollBearPig
  • 496
  • 1
  • 7
  • 17
3

In Hybernate 6, new features have been added like the SqlTypes.JSON. So, you could have "jsonb" in your field like this:

@JdbcTypeCode(SqlTypes.JSON)
@Column(columnDefinition = "jsonb") 
private ArrayList<Account> accounts;
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • 1
    I've been finding JSONb types are difficult to query against. Hibernate doesnt make it easy, basically forcing raw query types unfortunately. – TrollBearPig Apr 21 '23 at 00:31
2

In Hibernate 6, the mapping annotations are much more typesafe. You're usually required to specify Class references instead of stringly-typed names.

Gavin King
  • 3,182
  • 1
  • 13
  • 11
0

If you want to model JSON, I would suggest you to use @JdbcTypeCode(SqlTypes.JSON) which is how you model JSON with plain Hibernate ORM Core. Also see https://docs.jboss.org/hibernate/orm/6.1/userguide/html_single/Hibernate_User_Guide.html#basic-mapping-json

Christian Beikov
  • 15,141
  • 2
  • 32
  • 58