使用 @Type 在 Hibernate >6 中处理二进制数据

huangapple go评论74阅读模式
英文:

Using @Type for Binary data in Hibernate >6

问题

我正在进行一门使用Spring Boot 2.19、Hibernate 5.3.12和Java 8编写的Spring Boot课程。
我正在使用Java 17、Hibernate 6.1.6和Spring Boot 3.0.2。

我已经解决了许多不匹配的问题,但有一个问题我找不到解决方案:

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

显然在Hibernate 6之后被弃用(我得到错误"无法解析方法type")

然而,我找到的解决方案都与二进制数据无关,而且在文档中也找不到相关的信息...我猜这是因为我对这个领域还很陌生,所以当答案出现时,我可能看不到它!

根据各种来源,我尝试了:

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

IDE在这两种情况下都没有为Binary建议任何内容...

我猜我可以只下载较低版本的Hibernate依赖,但我还是很好奇,在最新的Hibernate版本中这是如何工作的?

英文:

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

得分: 11

@JdbcType(VarbinaryJdbcType.class)

或:

@JdbcTypeCode(Types.VARBINARY)

英文:

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

@JdbcType(VarbinaryJdbcType.class)

or:

@JdbcTypeCode(Types.VARBINARY)

答案2

得分: -2

在这种情况下,如果其他人遇到类似问题的话,似乎 Hibernate 6 自行处理了这种类型的转换,无需额外设置,因此只需删除属性即可解决问题:

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

问题似乎已解决,项目似乎正常运行。

英文:

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.

huangapple
  • 本文由 发表于 2023年2月6日 02:41:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75354646.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定