JPA entity:
@Entity data class Person( @NotBlank @Column(nullable = false) val firstName: String = "", @NotBlank @Column(nullable = false) val lastName: String = "", // other fields... )
Projection Views (interfaces and classes are possible to use):
interface PersonFirstNameInterfaceView { val firstName: String } data class PersonFirstNameClassView(val firstName: String)
JPA Repository (not By suffix in the end of method names):
interface PersonRepository : JpaRepository<Person, Long> { fun getAllFirstNamesBy(): List<PersonFirstNameInterfaceView> fun findOloloTrololoBy(): List<PersonFirstNameClassView> fun findAllBy(): List<PersonFirstNameInterfaceView> fun findBy(): List<PersonFirstNameInterfaceView> fun getBy(): List<PersonFirstNameClassView> }
Run tests:
./mvnw clean test