【发布时间】:2019-07-16 15:10:04
【问题描述】:
我想同时发布一个对象,从关系的引用表中返回数据。
关系定义如下:
@Entity
@Table( name = "application")
public class Application {
@Id
@JsonIgnore
private Long id;
@ManyToOne
@JoinColumn(name = "product_category")
private ProductCategory productCategory;
...
}
还有:
@Entity
@Table(name = "product_category")
public class ProductCategory {
@Id
@Column(name = "product_category_id")
private Long productCategoryId;
@Column(name = "description")
private String description;
@JsonIgnore
@OneToMany(mappedBy = "productCategory")
private Set<Application> applications;
...
}
我的 product_category 表有以下数据:
在使用以下结构发布我的 Json 对象时:
...
{
"productCategory": "0"
}
...
我想得到以下 json 输出:
...
"productCategory": {
"productCategoryId": 0,
"description": "Personal Loan"
},
...
但我得到的是:
...
"productCategory": {
"productCategoryId": 0,
"description": null
},
...
你能建议吗?
【问题讨论】:
-
你能贴出生成 json 响应的代码吗?
-
这只是一个简单的repository返回。 return applicationRepository.save(appRequest);
-
没有看到你的代码就无话可说
标签: java spring spring-boot hibernate hibernate-mapping