的特定列的实体,我有两个实体:休眠得到嵌套实体
@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;
}
如何获得Animal
具体Species
场,scientificName
例如?如何告诉Hibernate我只需要嵌套实体的特定字段?
期望中的动物:
{
"id": 1,
"nickname": "Locuroumee",
"species": {
"id": 161130,
"scientificName": "Anguilla bicolor",
}
实际的动物:
{
"id": 1,
"nickname": "Locuroumee",
"species": {
"id": 161130,
"scientificName": "Anguilla bicolor",
"animalsPerHouse": 4
}
我已经花了很多时间与预测,别名,但它并不能帮助
我也有类似的问题[这](http://stackoverflow.com/questions/12105757/complex-hibernate-projections) – hardcoder