title: Spring Data Rest and entities' IDs in relationships
body: <p>I'm working on a Spring Data Rest based Spring Boot service whose data model is similar to the one in the tutorial:
  <a href="https://www.baeldung.com/spring-data-rest-relationships" rel="nofollow noreferrer">https://www.baeldung.com/spring-data-rest-relationships</a></p>
  <p>(In defining the entities, I'm using Lombok annotations):</p>
  <pre><code>@Data
  @NoArgsConstructor
  @Entity
  @Table(name = &quot;cale&quot;)
  public class Book {
  
      @Id
      @GeneratedValue
      private long id;
  
      @Column(nullable=false)
      private String title;
  
      @ManyToOne
      private Library library;
  
  }
  
  
  @Data
  @NoArgsConstructor
  @Entity
  @Table(name = &quot;library&quot;)
  public class Library {
  
  
      @Id
      @GeneratedValue
      private long id;
      
      //...
  
  
  }
  </code></pre>
  <p>invoking the endpoint <code>/books</code> I get the following json:</p>
  <pre><code>{
        &quot;_embedded&quot;: {
          &quot;books&quot;: [
            {
              &quot;id&quot;: 22,
              &quot;title&quot;: &quot;The title of the book&quot;,
              &quot;_links&quot;: {
                &quot;self&quot;: {
                  &quot;href&quot;: &quot;http://192.168.33.20:8080/books/22&quot;
                },
                &quot;book&quot;: {
                  &quot;href&quot;: &quot;http://192.168.33.20:8080/books/22&quot;
                },
                &quot;library&quot;: {
                  &quot;href&quot;: &quot;http://192.168.33.20:8080/books/22/library&quot;
                }
              }
            },
            .
            .
            .
  </code></pre>
  <p>in HAL style, the only reference to the library linked to a given book is through an URL like <code>http://192.168.33.20:8080/books/22/library</code></p>
  <p>In order to get the id of the library associated to book 22, I have to perform a second GET call to the URL, which is inefficient in many cases.</p>
  <p>Moreover, this makes it very hard to implement queries like &quot;<em>GET all books associated to the library whose id is 101</em>&quot;.</p>
  <p>Is there a way to let Spring Data Rest include also the id of the associated entity into the returned json? Something like:</p>
  <pre><code>{
        &quot;_embedded&quot;: {
          &quot;books&quot;: [
            {
              &quot;id&quot;: 22,
              &quot;title&quot;: &quot;The title of the book&quot;,
              &quot;library_id&quot;: 101, 
              &quot;_links&quot;: {
              .
              .
              .
              }
            },
            .
            .
  </code></pre>