[英]spring-data-rest, manytomany relation with join table
Is it possible to expose a manytomany relationship that uses a join entity (that contains extra data columns), below is my entities; 是否可以公开使用连接实体(包含额外数据列)的多人关系,下面是我的实体;
I'm trying to get 'purchases' to show in REST, I've put in 'products' as an example of a working REST mapping; 我试图在REST中显示“购买”,我将“产品”作为工作REST映射的示例;
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, targetEntity = Purchase.class, orphanRemoval = true)
@JoinColumn(name = "user_id", updatable = false)
private List<Purchase> purchases = new ArrayList<>();
@ManyToMany
@JoinColumn(name = "user_id", updatable = false)
private List<Product> products = new ArrayList<>();
}
@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
}
@Entity
public class Purchase implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
@ManyToOne
@JoinColumn(name = "user_id", referencedColumnName = "id")
private User user;
@ManyToOne(targetEntity = Prodect.class)
@JoinColumn(name = "product_id", referencedColumnName = "id")
private Product product;
@Column(name = "purchase_date")
private Date purchaseDate;
}
So if i send the REST call; 所以,如果我发送REST呼叫;
[GET http://localhost:8080/webapp/users/1] [GET http:// localhost:8080 / webapp / users / 1]
It returns links for [http://localhost:8080/webapp/users/1/products] but not for [http://localhost:8080/webapp/users/1/purchases] 它返回[http:// localhost:8080 / webapp / users / 1 / products]的链接,但不返回[http:// localhost:8080 / webapp / users / 1 / purchases]的链接
worked out what the issue was; 弄清楚问题是什么; I need to create a JpaRepository for the Purchase entity.
我需要为Purchase实体创建一个JpaRepository。 Soon as I added that, the REST links for purchases are available.
我添加的时候,可以使用REST购买链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.