【发布时间】:2016-10-07 15:38:45
【问题描述】:
我有两个实体:
@Entity
@Table(name = "animals")
public class Animal extends BaseEntity {
private String nickname;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "species_id", nullable = false)
private Species species;
}
和
@Entity
@Table(name = "species")
public class Species extends BaseEntity {
private String scientificName;
private Integer animalsPerHouse;
}
如何使用特定的Species 字段获取Animal,例如scientificName?如何告诉 Hibernate 我只需要嵌套实体的特定字段?
想要的动物:
{
"id": 1,
"nickname": "Locuroumee",
"species": {
"id": 161130,
"scientificName": "Anguilla bicolor",
}
实际动物:
{
"id": 1,
"nickname": "Locuroumee",
"species": {
"id": 161130,
"scientificName": "Anguilla bicolor",
"animalsPerHouse": 4
}
我已经在投影、别名上花费了很多时间,但这无济于事
【问题讨论】:
-
我有类似的问题this
标签: hibernate projection