gpt4 book ai didi

java - @Column 和 @Enumerated 在嵌入实体中不起作用

转载 作者:行者123 更新时间:2023-11-30 06:19:38 25 4
gpt4 key购买 nike

我有主要实体:

@Entity
@Table(name = "partners")
public class Partner {
@ElementCollection
@CollectionTable(
name = "external_login",
joinColumns = @JoinColumn(name = "partner_id")
)
private List<ExternalLogin> externalLogins;
...
}

ExternalLogin是嵌入实体

@Embeddable
public class ExternalLogin {
@Column(name = "type")
@Enumerated(value = EnumType.STRING)
private ExternalLoginType type;
@Column(name = "login")
private String login;
@Column(name = "password_value")
private String passwordValue;
}

public enum ExternalLoginType {
ABC;
}

@Column@Enumerated 不适用于 ExternalLogin 实体。

例如,查询中将是 external_login.passwordValue 而不是 external_login.password_value

@Enumerated(value = EnumType.STRING) 也不起作用。 Hibernate 正在尝试获取字段的 int 值,而不是 string

有人可以帮助我吗?

最佳答案

您滥用了注释@Embeddable。请参阅 oracle 文档 https://docs.oracle.com/javaee/6/api/javax/persistence/Embeddable.html 中的描述

Defines a class whose instances are stored as an intrinsic part of an owning entity and share the identity of the entity. Each of the persistent properties or fields of the embedded object is mapped to the database table for the entit

@Embeddable 注释仅对单数关联字段有意义。将列表字段注释为 @Embeddable 是错误的。

直接替换即可

@Embeddable
public class ExternalLogin {

@Entity
public class ExternalLogin {

关于java - @Column 和 @Enumerated 在嵌入实体中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48456881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com