I have two entities:
@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;
}
and
@Entity
@Table(name = "species")
public class Species extends BaseEntity {
private String scientificName;
private Integer animalsPerHouse;
}
How to get Animal
with specific Species
field, scientificName
for example? How to tell to Hibernate that I need only specific fields of nested entity?
Desired animal:
{
"id": 1,
"nickname": "Locuroumee",
"species": {
"id": 161130,
"scientificName": "Anguilla bicolor",
}
Actual animal:
{
"id": 1,
"nickname": "Locuroumee",
"species": {
"id": 161130,
"scientificName": "Anguilla bicolor",
"animalsPerHouse": 4
}
I already spent much time with projections, aliases, but it doesn't help