jpql

spring boot data @query to DTO

淺唱寂寞╮ 提交于 2020-07-18 07:23:58
问题 I want to assign the result of a query to a DTO object. The DTO looks like this: @Getter @Setter @NoArgsConstructor public class Metric { private int share; private int shareholder; public Metric(int share, int shareholder) { this.share = share; this.shareholder = shareholder; } } And the query looks like the following: @RepositoryRestResource(collectionResourceRel = "shareholders", path = "shareholders") public interface ShareholderRepository extends PagingAndSortingRepository<Shareholder,

Spring JPA long SQL String for NativeQuery

↘锁芯ラ 提交于 2020-07-10 03:37:28
问题 In my Spring JPA Project, I have a repo file as such: @Repository public interface StudentRepository extends JpaRepository<Student, Integer>{ @Query(value = "select * from students", nativeQuery = true) public List<Student> findStudents( @Param("keyword") String keyword ); } With this, I can still copy paste the SQL and run in my DB software. But when it comes to large queries as such: @Query(value = "SELECT\n" + "*\n" + "FROM\n" + "students\n" + "WHERE\n" + "(\n" + "`id` LIKE CONCAT('%',

Is there an alternative for native query's 'GROUP_CONCAT' in JPQL with JPA?

拈花ヽ惹草 提交于 2020-07-09 09:20:55
问题 I am trying to fetch profile menus of a profile using jpql with JPA. My 'Profile' and 'ProfileMenus' entities have many to one relationship. I have tried looking into these answers but couldn't find any working solution. How to add non-standardized sql functions in Spring Boot application? Registering a SQL function with JPA and Hibernate https://vladmihalcea.com/hibernate-sql-function-jpql-criteria-api-query/ I also went through this link and seems to have same problem as mine, How to

JPQL: cast Long to String to perform LIKE search

隐身守侯 提交于 2020-06-24 22:55:31
问题 I have the following JPQL query: SELECT il FROM InsiderList il WHERE ( il.deleteFlag IS NULL OR il.deleteFlag = '0' ) AND il.clientId = :clientId AND ( LOWER( il.name ) LIKE :searchTerm OR il.nbr LIKE :searchTerm OR LOWER( il.type ) LIKE :searchTerm OR LOWER( il.description ) LIKE :searchTerm ) The customer wants us to be able to search be the nbr field, which is a java.lang.Long . Q : How do you perform a LIKE search on a java.lang.Long using JPQL? 回答1: You can use the CAST in HQL: SELECT il

JPQL: cast Long to String to perform LIKE search

旧巷老猫 提交于 2020-06-24 22:55:22
问题 I have the following JPQL query: SELECT il FROM InsiderList il WHERE ( il.deleteFlag IS NULL OR il.deleteFlag = '0' ) AND il.clientId = :clientId AND ( LOWER( il.name ) LIKE :searchTerm OR il.nbr LIKE :searchTerm OR LOWER( il.type ) LIKE :searchTerm OR LOWER( il.description ) LIKE :searchTerm ) The customer wants us to be able to search be the nbr field, which is a java.lang.Long . Q : How do you perform a LIKE search on a java.lang.Long using JPQL? 回答1: You can use the CAST in HQL: SELECT il