我创建了以下java类
产品.java
@Entity
public class Product {
@Id
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
@GeneratedValue(generator = "UUID")
private UUID id;
private String name;
@Lob
private String description;
private String category;
private String itemCode;
@OneToMany(mappedBy = "product")
private List<ProductFeatures> productFeatures;
@ManyToMany
@JoinTable(
name = "product_tags",
joinColumns = @JoinColumn(name = "product_id"),
inverseJoinColumns = @JoinColumn(name = "tag_id")
)
private List<Tag> productTags;
private int quantity;
private Timestamp dateModified;
@ManyToOne
@JoinColumn(name = "vendor_id")
private Vendor vendor;
}
和
标记.java
@Entity
public class Tag {
@Id
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
@GeneratedValue(generator = "UUID")
private UUID id;
private String name;
@Lob
private String description;
@ManyToMany(mappedBy = "productTags")
private List<Product> products;
}
这两个类将创建三个表 products、tags 和 product_tags。现在,我想为product_tags表创建一个存储库。我该怎么做呢?
如有任何建议,我们将不胜感激。
1条答案
按热度按时间b91juud31#
您不能。JpaRepository需要实体,但没有ProductTag实体。product_tag只是一个连接表,用于满足Product和Tag之间的ManyToMany关系。您需要的JpaReposories是Product和Tag