Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using @Type for Binary data in Hibernate >6

I am doing a Spring Boot course written in Spring Boot 2.19, Hibernate 5.3.12 and Java 8. I am using Java 17, Hibernate 6.1.6 and Spring Boot 3.0.2.

I sorted many things that didn't match, but one problem I can't find the solution to is that :

@Type(type="org.hibernate.type.BinaryType")

is apparently deprecated since Hibernate 6 (I get the error "Cannot resolve method type")

However, none of the solutions I found were related to binary data and I couldn't find anything relevant in the docs .. I guess because I'm so new to this area I probably can't see the answer when it hits me!

Based on various sources I tried:

@Convert(converter = org.hibernate.type.BinaryConverter.class)
@Type(BinaryType) 

IDE does not suggest anything for Binary.. in either of the cases..

I guess I could just download the lower version dependency of hibernate, but I am curious still how does this work in the newest Hibernate version?

like image 510
ISquared Avatar asked May 12 '26 18:05

ISquared


2 Answers

You have not really given enough information here, but probably the solution is:

@JdbcType(VarbinaryJdbcType.class)

or:

@JdbcTypeCode(Types.VARBINARY)
like image 196
Gavin King Avatar answered May 14 '26 09:05

Gavin King


@Type(type="org.hibernate.type.BinaryType") isn't working in Hibernate 6>

but if you are using for converting in byte[] type, you can just delete annotation @Lob and use @JdbcTypeCode(Types.BINARY).

like image 41
Mihai Dodi Avatar answered May 14 '26 10:05

Mihai Dodi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!