PostgreSQL 和 Spring Boot 3 出现问题,错误为“无法解析方法 ‘type’”。

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

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

&lt;properties&gt;
        &lt;java.version&gt;17&lt;/java.version&gt;
&lt;/properties&gt;

&lt;parent&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
        &lt;version&gt;3.0.4&lt;/version&gt;
&lt;/parent&gt;

&lt;dependency&gt;
            &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
            &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
            &lt;scope&gt;runtime&lt;/scope&gt;
&lt;/dependency&gt;

My Database column create:

    id character varying(255) COLLATE pg_catalog.&quot;default&quot; NOT NULL

old Version @Entity

    @Lob
    @Type(type = &quot;org.hibernate.type.ImageType&quot;)
    @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 = &quot;org.hibernate.type.ImageType&quot;)
@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 = &quot;org.hibernate.type.StringType&quot;)
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.

huangapple
  • 本文由 发表于 2023年3月21日 02:59:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75794270.html
匿名

发表评论

匿名网友

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

确定