18

I've just upgraded the version I use for Hibernate to 5.6.1 and it seems it's now deprecating some Type-related annotations:

@TypeDef(name = "json", typeClass = JsonBinaryType::class)


@Type(type = "json")

I found no documentation as to what to do except that

6.0 will introduce a new series of type-safe annotations to serve the same purpose

Our quality guidelines forces us to try and solve every warning and as such I would like to replace these annotations by a non deprecated use.

Crystark
  • 3,693
  • 5
  • 40
  • 61

3 Answers3

6

It seems there is no replacement until Hibernate 6. Type and also TypeDef was marked as deprecated to mark it as removed in version 6, but so far not replacement exists. The ideology here is that deprecated does not indicate that already a new version exists, which might be not an intuitive meaning for most developers.

This was reverted now in the current 5.6.3-Final version series.

k_o_
  • 5,143
  • 1
  • 34
  • 43
2

From this

import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
 
@TypeDef(name = "json", typeClass = StringJsonUserType.class)
public class EntityName {
 
 @Type(type = "json")
 private propertyName

to in hibernate 6

import jakarta.persistence.Convert;
import org.hibernate.annotations.JdbcTypeCode;
 
 
@Convert(attributeName = "entityAttrName", converter = StringJsonUserType.class)
public class EntityName {
 
 
 @JdbcTypeCode(SqlTypes.JSON)
 private propertyName
1

This deprecation has been reverted in Hibernate 5.6.3-Final

Dimi
  • 279
  • 1
  • 3
  • 11
  • I'd like to accept both answers but StackOverflow prevents me from doing so. In any case your answer combined to k_o_'s fully closes this question. Thanks. There is indeed no replacement and they did remove the deprecation as a patch because "it was wrong" :) – Crystark Jan 18 '22 at 14:10
  • 6
    In Hibernate 6, `@TypeDef` is removed and `@Type` is changed. Therefore it's not clear how to map a PostgreSQL enum type. I asked a question here — https://github.com/vladmihalcea/hibernate-types/issues/514. – Dmitriy Popov Nov 14 '22 at 18:03