0

我有以下实体

@Entity
public class Conversation implements Serializable {

    @Id
    private int Id;

    @Column
    private Alias AliasA;

    // SNIP
}

@Entity
public class Alias implements Serializable {

    @Id
    private String alias;

    @Column
    private String personalName;

    @OneToMany(mappedBy = "alias", cascade = CascadeType.ALL)
    @MapKeyColumn(name="address")
    private Map<String, Recipient> recipients = new HashMap<String, Recipient>();
}

@Entity
public class Recipient implements Serializable {

    @Id
    @GeneratedValue
    private long id;

    @Column
    private String address;

    @Column
    private RecipientStatus status;

    @ManyToOne
    private Alias alias;
}

我想做类似下面的 JPQL 查询

SELECT conversation FROM Conversation conversation WHERE :sender MEMBER OF conversation.aliasA.recipients AND conversation.adId=:adID

我的地图的键在哪里:sender。然而,该MEMBER OF关键字似乎只适用于集合而不适用于地图。我相信 JPA 2.0 应该提供KEY关键字,但这似乎还没有在 OpenJPA 中实现。有没有替代方案?

更新:添加信息以澄清我的问题。

4

2 回答 2

1

有一个VALUE关键字应该允许您执行以下操作:

SELECT c FROM Conversation c JOIN c.aliasA a JOIN a.recepients r 
WHERE VALUE(r) = :sender AND conversation.adId=:adID
于 2012-04-18T11:41:48.297 回答
0

虽然 axtavt 的回答给了我需要的提示,但实际上答案是,在这种情况下,IntelliJ 10.5.4 中的错误检查是不可信的。

KEY关键字确实有效,正确的查询是

SELECT conversation FROM Conversation conversation JOIN conversation.aliasA.recipients recipients WHERE KEY(recipients) = :senderAddress AND conversation.adId=:adID
于 2012-04-27T15:27:09.917 回答