2

以下是我希望创建连接的两个实体:

public class CustomFieldValue {
private Integer           id;
private Integer           identifier;
private String            entityName;
private String            name;
private String            value;

public CustomFieldValue() {
}

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
    return this.id;
}

public void setId(Integer id) {
    this.id = id;
}

@Column(name = "identifier", nullable = false)
public Integer getIdentifier() {
    return identifier;
}

public void setIdentifier(Integer identifier) {
    this.identifier = identifier;
}

@Column(name = "entity_name", nullable = false)
public String getEntityName() {
    return entityName;
}

public void setEntityName(String entity) {
    this.entityName = entity;
}

@Column(name = "name")
public String getName() {
    return value1;
}

public void setName(String name) {
    this.name = name;
}

@Column(name = "value")
public String getValue() {
    return value;
}

public void setValue(String value) {
    this.value = value;
}
}


class Order 
{
    int id;
    ...
    Set<CustomFieldValue> customFieldValues;

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
    return this.id;
}

public void setId(Integer id) {
    this.id = id;
}

public void setCustomFieldValues(Set<CustomFieldValue> customFieldValues) {
    this.customFieldValues = customFieldValues;
}

@OneToMany(fetch = FetchType.EAGER)
@JoinColumnsOrFormulas({
        @JoinColumnOrFormula(column = @JoinColumn(name = "identifier", referencedColumnName = "id", insertable = false, updatable = false)),
        @JoinColumnOrFormula(formula = @JoinFormula(value = "entityName='Order'")) })
public Set<CustomFieldValue> getCustomFieldValues() {
    return customFieldValues;
}
}

当 CustomFieldValue 中的标识符等于 Order id 并且 entityName 为“Order”时,我想创建一个连接。我在这一行收到一个错误:

@JoinColumnOrFormula(formula = @JoinFormula(value = "entityName='Order'"))

它说“在实体 Order 中找不到逻辑名称”,@JoinFormula 注释中唯一存在的其他属性是 referencedColumnName,我无法提供。

有什么想法可以实现吗?

4

0 回答 0