9

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?

1
  • I did, it says 'Cannot resolve symbol' for BinaryConverter Commented Feb 5, 2023 at 19:05

3 Answers 3

18

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

@JdbcType(VarbinaryJdbcType.class)

or:

@JdbcTypeCode(Types.VARBINARY)
Sign up to request clarification or add additional context in comments.

1 Comment

@JdbcTypeCode(Types.VARBINARY) This worked for me in saving a image bytes to postgres.
4

@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).

Comments

-3

Quick update in case anyone else encounters this, it appears Hibernate 6 is taking care of this exact type conversion on its own, without the need for additional settings, so simply getting rid off the attribute:

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

solved the problem and the project appears to be running fine.

3 Comments

It doesn't work for me, I had to use Gavin King answer
Simply deleting the added annotation can be a solution, thanks! By deleting @JdbcTypeCode(Types.BINARY) my UUID attribute is going to be persisted in the right way.
@ISquared: do you mean delete the whole ANNOTATION @Type? Or just the attribute "type"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.