英文:
Problem with Postgresql and Spring Boot 3 Error "Cannot resolve method 'type'"
问题
我正在将我的Spring Boot 2.7 JPA项目升级到Spring Boot 3。我在PostgreSQL数据库中保存了头像。
来自我的pom.xml摘录:
<properties>
<java.version>17</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.4</version>
</parent>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
我的数据库列创建:
id character varying(255) COLLATE pg_catalog."default" NOT NULL
旧版本的 @Entity:
@Lob
@Type(type = "org.hibernate.type.ImageType")
@Column(length = 20971520)
private byte[] avatar;
现在我收到以下错误:"Cannot resolve method 'type'"
我也尝试过:
@Lob
@Column(length = 20971520)
private byte[] avatar;
我该如何解决这个问题?谢谢。
英文:
I am updating my spring boot 2.7 JPA project to Spring boot 3.
I saved avatars in a postgresql database.
excerpt from my pom.xml
<properties>
<java.version>17</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.4</version>
</parent>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
My Database column create:
id character varying(255) COLLATE pg_catalog."default" NOT NULL
old Version @Entity
@Lob
@Type(type = "org.hibernate.type.ImageType")
@Column(length = 20971520)
private byte[] avatar;
Now I get the following error
"Cannot resolve method 'type'"
I've tried too:
@Lob
@Column(length = 20971520)
private byte[] avatar;
How do I solve the problem?
Thanks
答案1
得分: 1
我找到了解决这个问题的方法:
旧版本
@Lob
//20 MB
@Type(type = "org.hibernate.type.ImageType")
@Column(length = 20971520)
private byte[] avatar;
新版本
@Lob
@JdbcTypeCode(Types.LONGVARBINARY)
@Column(length = 20971520)
private byte[] avatar;
英文:
I found a solution to this problem:
OLD Version
@Lob
//20 MB
@Type(type = "org.hibernate.type.ImageType")
@Column(length = 20971520)
private byte[] avatar;
NEW Version
@Lob
@JdbcTypeCode(Types.LONGVARBINARY)
@Column(length = 20971520)
private byte[] avatar;
答案2
得分: 0
我必须将我的代码从:
@Lob
@Type(type = "org.hibernate.type.StringType")
private String note;
更改为:
@Lob
@JdbcTypeCode(Types.LONGVARCHAR)
private String note;
在你的情况下可能不起作用,但可能指引你朝正确的方向。
英文:
I had to change my code from:
@Lob
@Type(type = "org.hibernate.type.StringType")
private String note;
to:
@Lob
@JdbcTypeCode(Types.LONGVARCHAR)
private String note;
It may not work in your case but it may point you in the right direction.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论