1

I have this Document hibernate jpa entity with an 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

To get all the documents by expertId, I would like to have my document JPA repository interface method called:

fun findAllByExpertId(String expertId): List<Document>

But, the only way I found to do so is:

fun findAllByDocumentExpertIdExpertId(String expertId): List<Document>

Is there an other way to have a better name for this method?

louis amoros
  • 2,418
  • 3
  • 19
  • 40

1 Answers1

0

You could change the ID and column definition to:

    @EmbeddedId
    @NotNull
    val documentExpertKey: DocumentExpertKey,

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

So that your query could be:

    fun findAllByDocumentExpertKeyId(String expertId): List<Document>

That looks a little more normal to me.

Dovmo
  • 8,121
  • 3
  • 30
  • 44
  • I don't really want to add a @Column just for naming and neither set a label "id" for "expertId"... – louis amoros Sep 07 '18 at 16:37
  • You wouldn't be adding a new `@Column` in. You'd modify what you have. `Spring Data JPA` by default will associate the variable name with the column name, but you can name the variable name whatever you want and that's what `Spring Data JPA` will use for the dervied queries. Hopefully that makes sense – Dovmo Sep 07 '18 at 16:46