1

我有这个Documenthibernate jpa实体EmbeddedId

@Entity
data class Document(
        @EmbeddedId
        @NotNull
        val documentExpertId: DocumentExpertId,
        // other fields
)

@Embeddable
data class DocumentExpertId(

        @Column(nullable = false)
        val expertId: String,

        @Column(nullable = false)
        val name: String

) : Serializable

要通过 获取所有文档expertId,我希望调用我的文档 JPA 存储库接口方法:

fun findAllByExpertId(String expertId): List<Document>

但是,我发现这样做的唯一方法是:

fun findAllByDocumentExpertIdExpertId(String expertId): List<Document>

还有其他方法可以为这种方法取一个更好的名称吗?

4

1 回答 1

0

您可以将 ID 和列定义更改为:

    @EmbeddedId
    @NotNull
    val documentExpertKey: DocumentExpertKey,

    @Column(name = "expertId", nullable = false)
    val id: String,

这样您的查询可能是:

    fun findAllByDocumentExpertKeyId(String expertId): List<Document>

这对我来说看起来更正常一些。

于 2018-09-07T13:18:54.630 回答