Sql Spring JPA投影不适用于UUID类型?

Sql Spring JPA投影不适用于UUID类型?,sql,spring-boot,jpa,kotlin,Sql,Spring Boot,Jpa,Kotlin,我和Kotlin和Springboot有一个项目。 在此项目中,实体具有以下字段:id、name和parent。 我只想得到id和名称。所以我为那个实体做了一个投影界面视图 这是我的实体: @Entity data class Keyword( @Id @GeneratedValue(generator = "uuid2") @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(columnD

我和Kotlin和Springboot有一个项目。 在此项目中,实体具有以下字段:
id
name
parent
。 我只想得到
id
名称
。所以我为那个实体做了一个投影界面视图

这是我的实体:

@Entity
data class Keyword(

    @Id
    @GeneratedValue(generator = "uuid2")
    @GenericGenerator(name = "uuid2", strategy = "uuid2")
    @Column(columnDefinition = "BINARY(16)")
    var id: UUID? = null,

    @Column(columnDefinition = "BINARY(16)")
    var parent: UUID? = null,

    @NotBlank
    var name: String? = null

)
存储库:

@Repository
interface KeywordRepository: JpaRepository<Keyword, UUID> {

    @Query(value = "SELECT keyword.id, keyword.parent, keyword.name FROM keyword LEFT JOIN project_keyword ON project_keyword.keyword_id = keyword.id WHERE project_keyword.project_id LIKE :id", nativeQuery = true)
    fun findAllKeywordsByProjectId(id: UUID): MutableList<KeyWordView>
}
当我通过控制器类调用这个端点时。我得到这个输出:

 "list": [
      {
        "name": "MARINE MICROBIOTA",
        "id": "0,31,-36,77,29,123,66,-25,-127,-43,-31,83,104,-90,47,10"
      }
    ]
但是如果我在我的
KeywordView
界面中将
val-id:String
更改为
val-id:UUID
,我会得到以下错误:

{
  "code": 500,
  "data": null,
  "message": "Could not write JSON: Projection type must be an interface!; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Projection type must be an interface! (through reference chain: no.inmeta.ris.util.response.ResponseDto[\"data\"]->no.inmeta.ris.util.pagination.PageDto[\"list\"]->java.util.ArrayList[0]->com.sun.proxy.$Proxy199[\"id\"])",
  "status": "FAIL"
}
有人知道如何解决这个问题吗?我希望以UUID的形式接收UUID,而不是使用奇怪的格式


谢谢大家!

我想问题在于UUID类。当您的实体声明您定义了dir hibernate时,db中的列是二进制的(16)。我假设在接口投影中使用这种UUID类型不起作用,因为没有有效的映射信息(如何将长度为16字节的二进制数据转换为UUID类)。所以我假设您必须更改列的类型,或者必须使用string并编写一个函数来转换该字符串

另一种可能是为该表创建第二个实体,其中只包含所需的两个col。只要用第二把刀,就像你用你的投影一样

 "list": [
      {
        "name": "MARINE MICROBIOTA",
        "id": "0,31,-36,77,29,123,66,-25,-127,-43,-31,83,104,-90,47,10"
      }
    ]
{
  "code": 500,
  "data": null,
  "message": "Could not write JSON: Projection type must be an interface!; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Projection type must be an interface! (through reference chain: no.inmeta.ris.util.response.ResponseDto[\"data\"]->no.inmeta.ris.util.pagination.PageDto[\"list\"]->java.util.ArrayList[0]->com.sun.proxy.$Proxy199[\"id\"])",
  "status": "FAIL"
}