Spring数据右外连接

时间:2016-01-14 03:37:31

标签: mysql sql hibernate jpa spring-data

我有像这样的实体

@Entity
@Table(name="documentTermValue")
public class DocumentTermValue extends ModelBase {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

   @ManyToOne
   @JoinColumn(name="taxonomyTermId")
   private TaxonomyTerm term;

    @ManyToOne
    @JoinColumn(name="documentId")
    private Document document;

    @Column(insertable=false,updatable=false)
    private Long documentId;
}

@Entity
@Table(name="document")
public class Document extends ModelBase {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @OneToMany(mappedBy="document")
    private List<DocumentTermValue> termValues = new ArrayList<DocumentTermValue>();

}
@Entity
@Table(name="taxonomyTerm")
public class TaxonomyTerm extends ModelBase {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private Long id;

    @ManyToOne
    @JoinColumn(name="taxonomyId")
    private Taxonomy taxonomy;

    @Column(insertable=false,updatable=false)
    private Long taxonomyId;

    @OneToMany(mappedBy="term")
    private List<DocumentTermValue> termValues = new  ArrayList<DocumentTermValue>();

}
@Entity
@Table(name="taxonomy")
public class Taxonomy extends ModelBase {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @OneToMany(mappedBy="taxonomy", cascade=CascadeType.ALL)
    private List<TaxonomyTerm> terms = new ArrayList<TaxonomyTerm>();
}

我需要选择(DocumentTermValues的子集)右连接TaxonomyTerm 喜欢这个SQL语句

select * from (select * from document_term_value as dtv where   dtv.document_id=10) as B right join taxonomy_term as tt on B.taxonomy_term_id = tt.id where tt.taxonomy_id=1;

如何使用弹簧数据JPA进行操作? 我是否需要对原生SQL查询执行此选择?

0 个答案:

没有答案