簡體   English   中英

JPA /休眠:可以將List屬性關聯到jpql查詢嗎?

[英]JPA/Hibernate: It's possible to associate List attribute to a jpql query?

我有3張桌子:
發票(id,userReadeableNum,...)
順序(id,userReadeableNum,...)
InvoiceOrderRel(ID,invoceId,orderId,insertDate等)

我想使用userReadableNum of Order類在發票類上創建一個List屬性。

像這樣:

@Entity
@Table(name="INVOICE")
@Immutable
public class Invoice implements Serializable{

    @Id
    @Column(name="INV_ID")
    private long invId;
    //many attributes

    /*I know that this annotation does not exists, i want to know if there's something similar*/
    @ByQuery("select o.userReadableNum from Order o join o.invoiceOrderList iol where iol.order.invId = :invId") 
    private List<String> orderNums;
    //etc...

我從未聽說過類似的東西,但是您可以創建一個@ManyToMany關系來解決此問題。 JPA和hibernate將數據庫表視為實體,因此他們期望PK和FK。

通過@ManyToMany關系, orderNums屬性將需要為List<Order>而不是字符串列表。 InvoiceOrderRel將是您的InvoiceOrderRel表。

這是有關@ManyToMany映射的一些信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM