挑战: 我想创建一个查询,该查询选择与关键字 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;
}