的特定列的實體,我有兩個實體:休眠得到嵌套實體
@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