Spring JPA selecting specific columns

@Entity data class User( var id: Long, var name: String?, var age: Int, ... ) class UserSummary(var id:Long, var name:String?) interface UserRepository : JpaRepository<User, Long> { fun findOneById(id: Long): User? fun <VIEW> findOneById(id: Long, type: Class<VIEW>): VIEW? fun <VIEW> findByIdIn(ids: List<Long>, type: Class<VIEW>): List<VIEW> // Using @Query failed to narrow the select column by passing type // @Query("from org.example.User where id in :ids") // fun <VIEW>findByIds(@Param("ids") ids: List<Long>, type:Class<VIEW>): List<VIEW>

Read More →

How to access RDB with Spring Boot and Kotlin Various

Unlike Java, in the case of Kotlin, using JDBC directly does not become too redundant Data acquisition method 3 patterns EntityManager @Component class Clazz1( private val entityManager: EntityManager ){ fun procSomething() { val rows = entityManager.createNativeQuery(""" select id, field1 from table1 """).let { q -> q.resultList } } } JpaRepository @Entity data class AnyData( val id: Long, val field1: String ) interface AnyDataRepository : JpaRepository<AnyData, Long> { } @Component class

Read More →