Skip to content

Files

Latest commit

author
Michael
Feb 27, 2024
4d5b701 · Feb 27, 2024

History

History

queries

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Feb 27, 2024
Jan 9, 2021
Jan 7, 2021

Status

Project Status: WIP – Initial development is in progress

Module

This module presents different ways of how to interact with the database.

Features

  • Spring Boot and Java 15
  • JPA Criteria API
  • QueryDSL
  • HQL
  • Native Queries
  • Jooq
  • H2 in memory

Execute

Main program

Run the main method in the DemoApplication class.

Knowledge

JPA criteria queries

The JPA Criteria API provides an alternative way for defining JPA queries, which is mainly useful for building dynamic queries whose exact structure is only known at runtime.

@Query

Check QueryAnnotationRepository.java

Native

@Query(value = "select * from PERSON where POST_CODE between :zipFrom and :zipTo ORDER BY POST_CODE", nativeQuery = true)
List<Person> findPersonsInZipCodeRangeWithNativeQuery(final int zipFrom, final int zipTo);

JPQL

@Query(value = "SELECT p FROM PERSON p WHERE p.postCode BETWEEN :zipFrom AND :zipTo")
List<Person> findPersonsInZipCodeRangeWithJPQ(final int zipFrom, final int zipTo, Sort sort);

Additional

Pagination

BEAM to documentation

Pagination allows to just return a subset of a whole result in a Page. This is useful when navigating through several pages of data on a web page.

Another advantage of pagination is that the amount of data sent from server to client is minimized.

public interface Pageable {

// number of the current page  
int getPageNumber();

int getPageSize();

Sort getSort();

// ... more methods
}

Sort

You can choose between various Sort functions and give this as a parameter.