JPA @Type注解 “无法解析方法 ‘type’ “

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

JPA @Type annotation "Cannot resolve method 'type' "

问题

在 @Type 接口上,我发现没有名为 type 的方法。有没有解决这个错误的方法?

JPA @Type注解 “无法解析方法 ‘type’ “

@Entity
@Table(name = "Delivery_Table")
public class Delivery {
@Id
@GeneratedValue
@Column(name = "Delivery_Id")
private Long id;

@Nationalized
private String name;
@Column(name = "address_full", length = 500)
private String address;
private LocalTime Delivery_time;
// 问题出现在这里
// 在 pom.xml 上配置了 JPA,其中已经存在 Hibernate
@Type(type = "yes_no")
private Boolean completed;

}

英文:

I was working on a project and found that on the @Type interface, there is no method called type. Is there any way to resolve the error?

JPA @Type注解 “无法解析方法 ‘type’ “

@Entity
@Table(name = "Delivery_Table")
public class Delivery {
    @Id
    @GeneratedValue
    @Column(name = "Delivery_Id")
    private Long id;

    @Nationalized
    private String name;
    @Column(name = "address_full",length = 500)
    private String address;
    private LocalTime Delivery_time;
    //Problem occurs here
    //Configuration on pom.xml used JPA where Hibernate is already there
    @Type(type = "yes_no")
    private Boolean completed;

}

答案1

得分: 1

如果是的话,您展示的源代码适用于Hibernate 5或之前版本。Hibernate 6在类型系统中有重大变化,@Type中不再有type属性,您需要根据迁移指南将其迁移到使用相关的JPA标准AttributeConverter(例如YesNoConverter):

@Convert(converter=YesNoConverter.class)
private Boolean completed;
英文:

Guess that you are using Hibernate 6 ?

If yes, the source codes you show is for Hibernate 5 or before. Hibernate 6 has the breaking change in the type system , there are no more type attribute in the @Type , you have to migrate it to use the related JPA standard AttributeConverter (i.e YesNoConverter) according to the migration guide :

> Hibernate now provides standard AttributeConverter implementations for
> handling different database representations as boolean values in the
> domain model

Change to the following should solve your problem :

 @Convert(converter=YesNoConverter.class)
 private Boolean completed;

huangapple
  • 本文由 发表于 2023年7月23日 15:45:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76747138.html
匿名

发表评论

匿名网友

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

确定