【发布时间】:2018-04-23 16:29:04
【问题描述】:
我有以下课程:
@Entity
public class EventOrderLine {
@EmbeddedId private EventOrderLineId id;
}
@Embeddable
public class EventOrderLineId implements Serializable {
@ManyToOne
@JoinColumn(name = "eventid")
@JsonIgnore
private Event event;
@ManyToOne
@JoinColumn(name = "orderlineid")
@JsonIgnore
private OrderLine orderLine;
}
@Entity
public class OrderLine {
@OneToMany
@JoinColumn(name = "orderlineid")
@JsonIgnore
private List<EventOrderLine> eventOrderLines = new ArrayList<>()
}
基本上我正在尝试通过 Criteria API 加入这两个表,但由于这是我想要做的,所以遇到了问题:
Root eventOrderLine = criteriaQuery.from(EventOrderLine.class);
Join orderLine = eventOrderLine.join("orderLine");
当然这给了我这个问题,因为映射不是直接在实体本身上:
Unable to locate Attribute with the the given name [orderLine] on this ManagedType [com.EventOrderLine]
我一直在尝试调整连接以深入研究 embeddedId,但不确定是否需要更进一步并修改我的实体的映射方式。我觉得这可能是我想念的一些简单的东西,但很难找到这个特定的问题。
【问题讨论】:
-
你试过
eventOrderLine.join("id").join("event")吗? -
我相信这是正确的解决方案!我知道这很简单。如果您将此评论作为答案,我会接受。
标签: java hibernate jpa relational-database criteria-api