拥有@JoinTable(“commit_reference_issue”)的自己的类,我需要使用名为“commit_reference_issue”的表进行连接,并使用非自有类Issue表示的表“issue”。我需要的联接是在课程问题之后显示的。
@Entity
@Table(name="commit")
@NamedQuery(name="Commit.findAll", query="SELECT c FROM Commit c")
public class Commit implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="sha", nullable=false, length=45)
private String sha;
//code omitted...
//bi-directional many-to-many association to Issue
@ManyToMany
@JoinTable(name="commit_reference_issue",
joinColumns = {
@JoinColumn(name="commit_sha", nullable=false, referencedColumnName = "sha")
},
inverseJoinColumns={
@JoinColumn(name = "issue_number", referencedColumnName = "number"),
@JoinColumn(name = "issue_repository_id_git", referencedColumnName = "repository_id_git")
}
)
private List<Issue> issues;
//code omitted...
非自有类问题
@Entity
@Table(name="issue")
@IdClass(IssuePK.class)
@NamedQuery(name="Issue.findAll", query="SELECT i FROM Issue i")
public class Issue implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "number")
private int number;
@Id
@ManyToOne
@JoinColumn(name = "repository_id_git", referencedColumnName = "id_git")
private Repository repository;
//code omitted...
//bi-directional many-to-many association to Commit
@ManyToMany(mappedBy="issues")
private List<Commit> commits;
//code omitted...
如何将此查询翻译为jpa eclipselink中的查询?
的
SELECT i.* FROM issue i INNER JOIN commit_reference_issue cri
ON i.number = cri.issue_number AND
i.repository_id_git = cri.issue_repository_id_git;
答案 0 :(得分:1)
谢谢@Chris!这项工作!我只在JPQL中添加一个子句,因为数据库有许多存储库。 所以这个JPQL是:
“从问题i中选择i加入i.commits c其中i.repository =:arg1”,其中“arg1”是存储库存储库。