QUERY for JOIN a @JoinTable in a @ManyToMany relationship with the non-owned table, in eclipselink jpa -
the own class @jointable ("commit_reference_issue"), need make join table called "commit_reference_issue" , table "issue" represented non-own class issue. join need show after class issue.
@entity @table(name="commit") @namedquery(name="commit.findall", query="select c 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 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...
the non-own class issue
@entity @table(name="issue") @idclass(issuepk.class) @namedquery(name="issue.findall", query="select 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 commit @manytomany(mappedby="issues") private list<commit> commits; //code omitted...
how can translate query below query in jpa eclipselink?
select i.* issue inner join commit_reference_issue cri on i.number = cri.issue_number , i.repository_id_git = cri.issue_repository_id_git;
thanks @chris! work! add clause in jpql, because database has many repositories. jpql is:
"select issue join i.commits c i.repository =:arg1", "arg1" repository repository.
Comments
Post a Comment