我有这个Document
hibernate 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>
还有另一种方法可以为这种方法提供更好的名称吗?
您可以将ID和列定义更改为:
@EmbeddedId
@NotNull
val documentExpertKey: DocumentExpertKey,
@Column(name = "expertId", nullable = false)
val id: String,
这样您的查询可能是:
fun findAllByDocumentExpertKeyId(String expertId): List<Document>
这对我来说看起来更正常。