以下是我要创建联接的两个实体:
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中找到逻辑名',@ JooFormula注释中唯一的其他属性是referencedColumnName,我无法提供。
有关如何实现这一目标的任何想法?