英文:
JPA @Type annotation "Cannot resolve method 'type' "
问题
在 @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?
@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;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论