进行SQL / JPQL查询以选择与两个关键字都匹配的所有主题

时间:2018-09-27 00:11:28

标签: sql jpql

挑战: 我想创建一个查询,该查询选择与关键字 ID的“ Java”和“ sql” ID为 1的主题关键字 “ Java”和“ Sql ”都匹配。

我已经实现了两个简单的实体 主题和关键字。它们具有双向的ManyToMany关系:

<div id="grid">
    <div id="imgh">
        <h1>Header Text</h1>
    </div>
    <div id="cont">
        <p>this is a paragraph</p>
    </div>
</div>

这是结构表。

这是@Entity @Table(name = "Topic") public class Topic implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "topicID") private Long id; @Column(name = "topicTitle") private String title = ""; @ManyToMany @JoinTable(name = "Join_Topic_Keyword", joinColumns = @JoinColumn(name = "Topic_ID"), inverseJoinColumns = @JoinColumn(name = "Keyword_ID")) private Set<Keyword> keywords; } @Entity @Table(name = "Keyword") public class Keyword implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "keywordID") private String id; @ManyToMany(mappedBy = "keywords") private Set<Topic> topics; }

的结果

0 个答案:

没有答案