Efficient lazy load approach for entities containing clob in hibernate

Overview

Lazy loading clob fields of Entites using Hibernate

This is an efficient approach to load clob fields lazily of an Entity. Using this approach,

  • distinct operation over the entities can be executed.
  • avoid (n + 1) queries while fetching the clob fields.

How to

  1. Maintain two separate Entities (one is with clob field, another one is without clob field) pointing to the same database table.
  2. In service layer, fetch the entities according to the search parameters without clob field. As clob field is not considering in this entity, We can run distinct operation if it is needed.
  3. We can get the ids of the entities fetched in step 2. Afterwards, we can fetch the entities with clob field by the ids in the same persistent context.
distinctNewsSpecification = Specification.where(NewsSpecification.titleEquals(title)) .and(NewsSpecification.distinct()); Page pagedNews = newsRepository.findAll(distinctNewsSpecification, page); // get the news ids which are fetched List newsIds = pagedNews.getContent().stream().map(news -> news.getNewsId()) .collect(Collectors.toList()); // fetch the news (with content clob) of the news ids Specification newsWithContentSpecification = Specification.where(NewsWithContentSpecification.newsIdIn(newsIds)); List newsWithContent = newsWithContentRepository.findAll(newsWithContentSpecification); return new PageImpl (newsWithContent, pagedNews.getPageable(), pagedNews.getTotalElements()); }">
@Transactional(readOnly = true)
public Page
        
          getNewsWithContent(Map
         
           parameters, Pageable page) {
    // Fetch the news (without content clob) using the search parameters
    // run distinct if we want to fetch distinct news
    String title = parameters.getOrDefault("title", null);
    Specification
          
            distinctNewsSpecification =
            Specification.where(NewsSpecification.titleEquals(title))
                         .and(NewsSpecification.distinct());
    Page
           
             pagedNews = newsRepository.findAll(distinctNewsSpecification, page);
    // get the news ids which are fetched
    List
            
              newsIds = pagedNews.getContent().stream().map(news -> news.getNewsId()) .collect(Collectors.toList()); // fetch the news (with content clob) of the news ids Specification
             
               newsWithContentSpecification = Specification.where(NewsWithContentSpecification.newsIdIn(newsIds)); List
              
                newsWithContent = newsWithContentRepository.findAll(newsWithContentSpecification); return new PageImpl
               
                (newsWithContent, pagedNews.getPageable(), pagedNews.getTotalElements()); } 
               
              
             
            
           
          
         
        
You might also like...

An IDE built specifically for Modding Minecraft Java Edition, containing many useful features that will be helpful for modders.

Modding-IDE An IDE built specifically for Modding Minecraft Java Edition, containing many useful features that will be helpful for modders. Trello: ht

Jul 16, 2022

Jornada Big Tech: I will have 3 months to study and prepare myself for the Big Tech interviews. Repository containing all my study material.

Jornada Big Tech: I will have 3 months to study and prepare myself for the Big Tech interviews. Repository containing all my study material.

Jornada Big Tech (Big Tech Journey) Jornada Big Tech: I will have 3 months to study and prepare myself for the Big Tech interviews. Repository contain

Dec 8, 2022

An IDE built specifically for Modding Minecraft Java Edition, containing many useful features that will be helpful for modders.

Railroad IDE Railroad IDE is an IDE that is made specifically for Minecraft Development including Forge Mods, and Fabric Mods! This IDE is made to hel

Dec 8, 2022

Annotation/Reflection Based Bukkit Command API. Containing many features such as help-service, command providers, tab completion, and many more!

CommandAPI Annotation/Reflection Based Command API that just does what you want it to do without any problems. Importing Maven repository id

Jun 13, 2022

Ribbon is a Inter Process Communication (remote procedure calls) library with built in software load balancers. The primary usage model involves REST calls with various serialization scheme support.

Ribbon Ribbon is a client side IPC library that is battle-tested in cloud. It provides the following features Load balancing Fault tolerance Multiple

Jan 1, 2023

AWS Service registry for resilient mid-tier load balancing and failover.

Eureka Eureka is a REST (Representational State Transfer) based service that is primarily used in the AWS cloud for locating services for the purpose

Dec 30, 2022

Ribbon is a Inter Process Communication (remote procedure calls) library with built in software load balancers. The primary usage model involves REST calls with various serialization scheme support.

Ribbon Ribbon is a client side IPC library that is battle-tested in cloud. It provides the following features Load balancing Fault tolerance Multiple

Jan 4, 2023

A simple JavaFX application to load, save and edit a CSV file and provide a JSON configuration for columns to check the values in the columns.

A simple JavaFX application to load, save and edit a CSV file and provide a JSON configuration for columns to check the values in the columns.

SmartCSV.fx Description A simple JavaFX application to load, save and edit a CSV file and provide a JSON Table Schema for columns to check the values

Oct 24, 2022

a reverse proxy load balancer using Java. Inspired by Nginx.

a reverse proxy load balancer using Java. Inspired by Nginx.

Project Outline: Project Main coding reverse proxy support configuration adding unit test works on Websocket Stress Test compared to Nginx load balanc

Aug 5, 2022

Minecraft mod running on the TTCp engine to load modules written in JS at runtime - with runtime deobfuscation!

PolyFire ClickGUI opens with NUMROW_0 How to use: Run -jsmodules to initialize Navigate to your .minecraft folder Go to config/pf/modules/ Copy Exampl

Nov 18, 2022

DbLoadgen: A Scalable Solution for Generating Transactional Load Against a Database

 DbLoadgen: A Scalable Solution for Generating Transactional Load Against a Database

DbLoadgen: A Scalable Solution for Generating Transactional Load Against a Database DbLoadgen is scalable solution for generating transactional loads

Feb 23, 2022

A simple plugin to load behavior packs from the 'behavior_packs' folder.

Behaviour Pack Loader for Nukkit A simple plugin to load behavior packs from the behavior_packs folder. If you found any bugs or have any suggestions,

Dec 7, 2022

Firehose is an extensible, no-code, and cloud-native service to load real-time streaming data from Kafka to data stores, data lakes, and analytical storage systems.

Firehose - Firehose is an extensible, no-code, and cloud-native service to load real-time streaming data from Kafka to data stores, data lakes, and analytical storage systems.

Dec 22, 2022

⚓ A simple chunk load plugin

MineChunks MineChunks is a simple plugin to laod chunks on a per player basis. It allows a player to define chunks in which will remain loaded so that

Oct 22, 2022

ActiveJ is an alternative Java platform built from the ground up. ActiveJ redefines web, high load, and cloud programming in Java, featuring ultimate performance and scalability!

Introduction ActiveJ is a full-featured modern Java platform, created from the ground up as an alternative to Spring/Micronauts/Netty/Jetty. It is des

Jan 7, 2023

Gatling is a load test tool. It officially supports HTTP, WebSocket, Server-Sent-Events and JMS.

Gatling is a load test tool. It officially supports HTTP, WebSocket, Server-Sent-Events and JMS.

Gatling What is Gatling ? Gatling is a load test tool. It officially supports HTTP, WebSocket, Server-Sent-Events and JMS. Motivation Finding fancy GU

Dec 27, 2022

Apache JMeter - An Open Source Java application designed to measure performance and load test applications

Apache JMeter - An Open Source Java application designed to measure performance and load test applications

An Open Source Java application designed to measure performance and load test applications. By The Apache Software Foundation What Is It? Apache JMete

Jan 1, 2023
Owner
Sheikh Al Amin Sunoyon
Sheikh Al Amin Sunoyon
Dynamically filters JPA entities with a simple query syntax. Provides JPA/Hibernate predicates and Spring Data specifications.

Spring Filter You need a way to dynamically filter entities without any effort? Just add me to your pom.xml. Your API will gain a full featured search

Turkraft 142 Dec 13, 2022
lazy-language-loader improves loading times when changing your language by only reloading the language instead of all the game resources!

lazy-language-loader lazy-language-loader improves loading times when changing your language by only reloading the language instead of all the game re

Shalom Ademuwagun 7 Sep 7, 2022
A simple quarkus app with hibernate as ORM, used to show the features of Hibernate Search

beer-manager-hibernate-search Project This project uses Quarkus, the Supersonic Subatomic Java Framework. If you want to learn more about Quarkus, ple

Sedona Solutions 3 Jan 6, 2022
ReDoSHunter: A Combined Static and Dynamic Approach for Regular Expression DoS Detection

ReDoSHunter ReDoSHunter is a combined static and dynamic approach for regular expression DoS detection. LATEST NOTE (updated at 2021.09.13): ReDoSHunt

Yeting Li 43 Dec 23, 2022
Car-Sequencing-Problem - Car-Sequencing Problem solved with Constraint Programming approach

Car-Sequencing problem solved with Constraint Programming : Problem Description : Cars in a production line can be configured with various options. A

Anas OUBAHA 4 Sep 7, 2022
ORM16 is a library exploring code generation-based approach to ORM for Java 17 and focusing on records as persistent data model

About ORM16 ORM16 is a library exploring code generation-based approach to ORM for Java 17 and focusing on records as persistent data model. Example I

Ivan Gammel 1 Mar 30, 2022
An experimental mod that converts some block entities to blockstates. This is done for performance & functionality reasons.

BetterBlockStates An experimental mod that converts some block entities to blockstates. This is done for performance & functionality reasons. Current

Fx Morin 10 Sep 17, 2022
A mod that lets you create "contracts" that transfer ownership of pets and other tameable entities.

Pet Transfer A simple mod for Fabric that lets you create contracts that can transfer ownership of pets and other tameable creatures. No Forge port pl

Emirikol 2 Jan 14, 2022
Serializes Entities, Basically converting them to namespacedkeys that can be used later, not exactly serializing with its common definition

Serializes Entities, Basically converting them to namespacedkeys that can be used later, not exactly serializing with its common definition

2Hex 2 Apr 3, 2022
A JavaFX library containing tiles that can be used for dashboards.

TilesFX A JavaFX library containing tiles for Dashboards. Donations are welcome at Paypal Intro The Tile is a simple JavaFX Control that comes with di

Gerrit Grunwald 1.3k Dec 30, 2022