[英]JPA Named query using object properties
I am trying to figure out how to create a (named?) query that will join my entities together. 我试图弄清楚如何创建将实体连接在一起的(命名?)查询。 Can I use object properties for the new entity and still do this?
我可以将对象属性用于新实体并且仍然这样做吗? I can't seem to decipher how that will/should look.
我似乎无法破译这种外观。
I have 2 tables, an order and order_assoc table. 我有2个表,一个order和order_assoc表。 For ever re-order created in the order table an entry will be created in order_assoc.
对于在订单表中创建的重新订购,将在order_assoc中创建一个条目。 Also, a re-order can be based on a previous order.
同样,重新排序可以基于先前的顺序。 So, I have a column in order_assoc that tells me the order which it was based on.
因此,我在order_assoc中有一列,告诉我它所基于的顺序。
For example, a re-order 4 is created which was based on a previous 1. So, now the assoc table will look like. 例如,创建一个基于先前1的重新排序4。因此,现在的assoc表将如下所示。
order order_assoc
------ -------------
1 new 1 <-pk 4 1
2 new
3 new
4 reorder
I have an existing entity class for order. 我有一个现有的实体类用于订购。 I added a reference (new entity) to the assoc table
我向assoc表添加了一个引用(新实体)
@OneToOne(fetch = FetchType.LAZY, optional = true, cascade = {CascadeType.ALL},
mappedBy = "onlineAdoptionEntity", targetEntity = OnlineAdoptionReOrderAssocEntity.class)
private OnlineAdoptionReOrderAssocEntity reOrderAssocEntity;
The new entity looks like this. 新实体看起来像这样。
@Id
@Column(name = "OA_REORDER_ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "reOrderNumberSeq")
@SequenceGenerator(name = "reOrderNumberSeq", sequenceName = "REORDER_NUMBER_SEQ", allocationSize=1)
private Long id;
@OneToOne(optional = true,cascade = CascadeType.ALL)
@JoinColumn(name="OA_ADOPTION_ID")
private OnlineAdoptionEntity onlineAdoptionEntity;
@ManyToOne(optional = true)
@JoinColumn(name="OA_ORIGINAL_ADOPTION_ID_ASSOC")
private OnlineAdoptionEntity baseReOrderAdoption;
Any help would be great thanks very much. 非常感谢任何帮助。 I saw there was a similar post here - it is just not clear to me after reading this post.
我看到有一个类似的帖子在这里 -它只是我不清楚阅读这篇文章之后。
I think what you're looking for is join operator: 我认为您正在寻找的是join运算符:
SELECT ro FROM Order ro
INNER JOIN o.reOrderAssocEntry roa
INNER JOIN roa.baseReOrderAdoption bo
bo.key = :value
I recommend reading JPQL Language reference 我建议阅读JPQL语言参考
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.