Skip to content

This poro demonstrates how to use projections in spring data jpa with intefraces and data classes.

Notifications You must be signed in to change notification settings

daggerok/spring-data-jpa-projections

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Data JPA projections CI

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

About

This poro demonstrates how to use projections in spring data jpa with intefraces and data classes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages