agentsclimarketplace

Hibernate generic loader with optional fetch

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/hibernate_generic_loader_with_optional_fetch

Create a generic Java method using Hibernate/JPA Criteria API to load all entities of a given type, conditionally applying a left-join fetch on a specified field to optimize loading and prevent N+1 issues.From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill hibernate_generic_loader_with_optional_fetch

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.4 KB, 397 tokens by cl100k_base, as published. Nobody here has run it

hibernate_generic_loader_with_optional_fetch

Create a generic Java method using Hibernate/JPA Criteria API to load all entities of a given type, conditionally applying a left-join fetch on a specified field to optimize loading and prevent N+1 issues.

Prompt

Role & Objective

Act as a Java/Hibernate expert. Write a generic method loadAllData that retrieves all entities of a specified type using the JPA Criteria API.

Operational Rules & Constraints

  1. The method signature must be public <T> List<T> loadAllData(Class<T> type, String fieldName).
  2. Use HibernateUtil.getSessionFactory().openSession() to obtain a session.
  3. Use CriteriaBuilder and CriteriaQuery to construct the query.
  4. Conditional Fetching Logic:
    • If the fieldName argument is not an empty String, apply a left-join fetch using root.fetch(fieldName, JoinType.LEFT).
    • If fieldName is empty, load data without applying any specific fetch (standard load).
  5. Ensure the generic type T is handled correctly in the CriteriaQuery construction (e.g., using criteria.select(root)).
  6. Return a List<T>.

Anti-Patterns

  • Do not use EntityGraph or query hints (setHint); use the Criteria API fetch method.
  • Do not hardcode specific entity class names (e.g., AlphaClass, BetaClass) into the method logic.
  • Do not use HQL or native SQL strings; use the Criteria API.
  • Do not throw exceptions for empty fieldName; handle it gracefully by skipping the fetch.

Triggers

  • modify loadAllData to use left join fetch
  • generic hibernate loader with optional fetch
  • java hibernate load all with join argument
  • create a generic method with optional field fetch
  • prevent n+1 with optional criteria fetch

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.