Latest

Sharing gathered and analyzed programming knowledge over time

  • Published on
    The JPA repository offers an alternative method for returning custom objects called JPQL Constructor Expression. This method can be used to create a Bean class for specified fields or aggregated fields, such as grouping authors by age and finding the count of authors at each age. When implementing JPQL Constructor Expression, ensure to use the fully qualified name of the Bean or POJO class, use the "new" keyword before the constructor call, and pass arguments in the same order and type as in the constructor. This approach only works with non-native (JPQL) queries.
  • Published on
    This tutorial explores ways to divide a Java List, Set, or Iterable into batches. It covers creating custom batch list implementations, using Stream classes, Google Guava, and Apache Commons Collections. Each method includes examples and output. The tutorial emphasizes the importance of handling original collection changes and clarifies the difference between partitions and deep copies. Additionally, it provides the necessary dependencies for each library and demonstrates creating lists or iterables of batched data, ultimately facilitating traversal through the divided data. Also answers the question like, How to divide list in to batch?, How to divide Set or Iterable in to batch or partition?, How to convert List to List of List with java and it's library?
  • Published on
    JPA Projection is a way to retrieve selected fields out of all available fields of table/entity. You will get multiple way to select limited fields from multiple or all the fields available. This article have multiple way to archive projection like open and close projection with interface, projection with class and records, projection with derived query, native and non-native query.
  • Published on
    This content provides an overview of how to use Derived Query Methods in Spring JPA. Derived method names in the repository interface consist of two parts separated by the "By" keyword. The first part represents the instruction, while the second part contains criteria acting as SQL where conditions. Examples of different query methods, such as equal criteria, null equal criteria, true/false equal criteria, similarity criteria, greater/less criteria, in criteria, and combination of criteria with "And" and "Or" logical operators are provided. Additionally, the content explains sorting data using keywords and parameters. It also emphasizes the use of the "Sort" object for dynamic sorting functionality.
  • Published on
    This post presents methods for grouping User Defined Objects by one of their properties, commonly faced in coding. It offers examples using a POJO User class. Two approaches are described, traditional for loop grouping and using groupingBy Collectors of collection stream. Additionally, it covers arranging POGO by unique property using traditional Java and toMap Collectors of collection stream. These methods help minimize iterations when searching for the same type of property.
Subscribe to the newsletter