Reputation: 6185
Having an entity like:
@Entity
public class Player {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private long id;
private String userName;
@OneToMany(mappedBy="player", fetch=FetchType.EAGER)
private Set<Participation> participations;
public long getId() {
return id;
}
public String getUserName() {
return userName;
}
public Set<Participation> getParticipations() {
return participations;
}
}
When I access to url http://localhost:8080/rest/players/1 using a debugger I can see how getUserName is called (by the serializer I guess). The getId
and the getParticipations
are not called.
This behavior is ok for me, I mean, it's just curiosity, why these getters are not called?
Upvotes: 0
Views: 451
Reputation: 2322
Assosciations are exposed as hal-links in spring data-rest if the association type is not linked to a repository.
They are available under the HAL "_links" resource. (reference spring data-rest projections & excerpts).
Entity ids are also skipped (by default) as you can find the id in the corresponding self link.
For exposing the id you just need to configure your RepositoryRestConfigurerAdapter to expose the ids by using:
@Configuration
public class DataRestConfiguration extends RepositoryRestConfigurerAdapter {
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.exposeIdsFor(Entity.class);
}
}
Upvotes: 1