title: How to combine child entities in to single _embedded array when using InheritanceType.JOINED from JPA and Spring Data Rest within Spring Boot?
body: <p>I am using Spring Data JPA and Spring Data Rest with Spring Boot 1.5.10.  I have three classes annotated with <code>@Entity</code>: <code>Message</code>, <code>AMessage</code>, and <code>BMessage</code> (Figure 2, 3, 4).  Classes <code>AMessage</code> and <code>BMessage</code> extend <code>Message</code> class (Figure 1).  I have one <code>MessageRepository</code> that is exposed via Spring Data Rest.  When I make a request to get all messages at <code>http://host:port/messages</code>, I get a response that contains two separate arrays under <code>_embedded</code> object (one for AMessage and one for BMessage) even though I am retrieving data from the <code>/messages</code> endpoint (Figure 5).  I only want to retrieve columns from the <code>Message</code> Entity.  How can this be achieved?</p>
  
  <p>I have uploaded my code to <a href="https://github.com/mawk09/spring-jpa-rest" rel="nofollow noreferrer">github.com</a></p>
  
  <p><strong>Figure 1:</strong> Hierarchy</p>
  
  <pre><code>           Message
                |
     ----------------------
     |                    |
  AMessage             BMessage
  </code></pre>
  
  <p><strong>Figure 2:</strong> Message Class (Parent) </p>
  
  <pre><code>import javax.persistence.*;
  
  @Entity
  @Table(name = "MSG")
  @Inheritance(strategy = InheritanceType.JOINED)
  @DiscriminatorColumn(name = "TYPE")
  public class Message {
  
      @Id @GeneratedValue
      private Long id;
      private String messageColumn1;
      @Column(name = "TYPE", updatable = false, insertable = false)
      private String messageType;
  
      public String getMessageColumn1() {
          return messageColumn1;
      }
  
      public void setMessageColumn1(String messageColumn1) {
          this.messageColumn1 = messageColumn1;
      }
  
      public String getMessageType() {
          return messageType;
      }
  }
  </code></pre>
  
  <p><strong>Figure 3:</strong> AMessage Class (Child)  </p>
  
  <pre><code>import javax.persistence.*;
  
  @Entity
  @Table(name = "MSG_A")
  @Inheritance(strategy = InheritanceType.JOINED)
  @DiscriminatorValue("A")
  public class AMessage extends Message {
  
      private String messageAColumn1;
  
      public String getMessageAColumn1() {
          return messageAColumn1;
      }
  
      public void setMessageAColumn1(String messageAColumn1) {
          this.messageAColumn1 = messageAColumn1;
      }
  }
  </code></pre>
  
  <p><strong>Figure 4:</strong> BMessage Class (Child)  </p>
  
  <pre><code>import javax.persistence.*;
  
  @Entity
  @Table(name = "MSG_B")
  @Inheritance(strategy = InheritanceType.JOINED)
  @DiscriminatorValue("B")
  public class BMessage extends Message {
  
      private String messageBColumn1;
  
      public String getMessageBColumn1() {
          return messageBColumn1;
      }
  
      public void setMessageBColumn1(String messageBColumn1) {
          this.messageBColumn1 = messageBColumn1;
      }
  }
  </code></pre>
  
  <p><strong>Figure 5:</strong> Get messages response (aMessages and bMessages separated)<br>
  <code>http://localhost:8080/messages</code></p>
  
  <pre><code>{
    "_embedded": {
      "aMessages": [
        {
          "messageColumn1": "MColumn1",
          "messageType": "A",
          "messageAColumn1": "AColumn1",
          "_links": {
            "self": {
              "href": "http://localhost:8080/aMessage/1"
            },
            "aMessage": {
              "href": "http://localhost:8080/aMessage/1"
            }
          }
        }
      ],
      "bMessages": [
        {
          "messageColumn1": "MColumn1",
          "messageType": "B",
          "messageBColumn1": "BColumn1",
          "_links": {
            "self": {
              "href": "http://localhost:8080/bMessage/2"
            },
            "bMessage": {
              "href": "http://localhost:8080/bMessage/2"
            }
          }
        }
      ]
    },
    "_links": {
      "self": {
        "href": "http://localhost:8080/messages{?page,size,sort}",
        "templated": true
      },
      "profile": {
        "href": "http://localhost:8080/profile/messages"
      }
    },
    "page": {
      "size": 20,
      "totalElements": 2,
      "totalPages": 1,
      "number": 0
    }
  }
  </code></pre>