Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Spring Boot中使用InheritanceType.JOINED from JPA和Spring Data Rest时,如何将子实体合并到单个_嵌入式阵列中?_Jpa_Spring Boot_Spring Data Jpa_Spring Data Rest - Fatal编程技术网

在Spring Boot中使用InheritanceType.JOINED from JPA和Spring Data Rest时,如何将子实体合并到单个_嵌入式阵列中?

在Spring Boot中使用InheritanceType.JOINED from JPA和Spring Data Rest时,如何将子实体合并到单个_嵌入式阵列中?,jpa,spring-boot,spring-data-jpa,spring-data-rest,Jpa,Spring Boot,Spring Data Jpa,Spring Data Rest,我在SpringBoot1.5.10中使用SpringDataJPA和SpringDataREST。我有三个用@Entity注释的类:Message、AMessage和BMessage(图2、3、4)。类AMessage和BMessageextendMessageclass(图1)。我有一个MessageRepository,它通过SpringDataREST公开。当我请求在http://host:port/messages,即使我正在从/messages端点检索数据,我也会得到一个响应,该响应

我在SpringBoot1.5.10中使用SpringDataJPA和SpringDataREST。我有三个用
@Entity
注释的类:
Message
AMessage
BMessage
(图2、3、4)。类
AMessage
BMessage
extend
Message
class(图1)。我有一个
MessageRepository
,它通过SpringDataREST公开。当我请求在
http://host:port/messages
,即使我正在从
/messages
端点检索数据,我也会得到一个响应,该响应在
\u embedded
对象下包含两个单独的数组(一个用于AMessage,一个用于BMessage)(图5)。我只想从
消息
实体中检索列。如何做到这一点

我已将我的代码上载到

图1:层次结构

           Message
              |
   ----------------------
   |                    |
AMessage             BMessage
图2:消息类(父级)

图3:消息类(子类)

图4:b消息类(子类)

图5:获取消息响应(A消息和B消息分开)
http://localhost:8080/messages

{
  "_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
  }
}
{
  "_embedded": {
    "messages": [
      {
        "messageColumn1": "MColumn1",
        "messageType": "A",
        "messageAColumn1": "AColumn1",
        "_links": {
          "self": {
            "href": "http://localhost:8080/aMessages/1"
          },
          "aMessage": {
            "href": "http://localhost:8080/aMessages/1"
          }
        }
      },
      {
        "messageColumn1": "MColumn1",
        "messageType": "B",
        "messageBColumn1": "BColumn1",
        "_links": {
          "self": {
            "href": "http://localhost:8080/bMessages/2"
          },
          "aMessages": {
            "href": "http://localhost:8080/bMessages/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
  }
}

决心!为
AMessage
BMessage
创建了新的存储库。用
@RepositoryRestResource(collectionResourceRel=“messages”)
注释每个存储库。这导致在
上执行
GET
时,消息被合并到
\u嵌入式
对象下的单个数组中http://localhost:8080/messages

{
  "_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
  }
}
{
  "_embedded": {
    "messages": [
      {
        "messageColumn1": "MColumn1",
        "messageType": "A",
        "messageAColumn1": "AColumn1",
        "_links": {
          "self": {
            "href": "http://localhost:8080/aMessages/1"
          },
          "aMessage": {
            "href": "http://localhost:8080/aMessages/1"
          }
        }
      },
      {
        "messageColumn1": "MColumn1",
        "messageType": "B",
        "messageBColumn1": "BColumn1",
        "_links": {
          "self": {
            "href": "http://localhost:8080/bMessages/2"
          },
          "aMessages": {
            "href": "http://localhost:8080/bMessages/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
  }
}
{
  "_embedded": {
    "messages": [
      {
        "messageColumn1": "MColumn1",
        "messageType": "A",
        "messageAColumn1": "AColumn1",
        "_links": {
          "self": {
            "href": "http://localhost:8080/aMessages/1"
          },
          "aMessage": {
            "href": "http://localhost:8080/aMessages/1"
          }
        }
      },
      {
        "messageColumn1": "MColumn1",
        "messageType": "B",
        "messageBColumn1": "BColumn1",
        "_links": {
          "self": {
            "href": "http://localhost:8080/bMessages/2"
          },
          "aMessages": {
            "href": "http://localhost:8080/bMessages/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
  }
}