Skip to content

Modified GenericDaoJpa.java to sort readAll by id#2203

Merged
jo-elimu merged 1 commit intoelimu-ai:mainfrom
jeevakumar-m:2201-jeeva-sortbyid
May 30, 2025
Merged

Modified GenericDaoJpa.java to sort readAll by id#2203
jo-elimu merged 1 commit intoelimu-ai:mainfrom
jeevakumar-m:2201-jeeva-sortbyid

Conversation

@jeevakumar-m
Copy link
Copy Markdown
Contributor

Issue Number

  • Resolves # 2201

Purpose

  • Modification GenericDaoJpa.java to sort readAll by id

Technical Details

  • Modified GenericDaoJpa.java to sort readAll by id

Testing Instructions

  • Modified GenericDaoJpa.java to sort readAll by id

Screenshots

  • Modified GenericDaoJpa.java to sort readAll by id

Format Checks

Note

Files in PRs are automatically checked for format violations with mvn spotless:check.

If this PR contains files with format violations, run mvn spotless:apply to fix them.

@jeevakumar-m jeevakumar-m requested a review from a team as a code owner May 30, 2025 13:10
@jeevakumar-m jeevakumar-m requested review from jo-elimu, shiv810 and vuriaval and removed request for a team May 30, 2025 13:10
@codecov
Copy link
Copy Markdown

codecov bot commented May 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 14.46%. Comparing base (2215316) to head (012aa34).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #2203   +/-   ##
=========================================
  Coverage     14.46%   14.46%           
  Complexity      403      403           
=========================================
  Files           243      243           
  Lines          6600     6600           
  Branches        757      757           
=========================================
  Hits            955      955           
  Misses         5594     5594           
  Partials         51       51           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 30, 2025

Walkthrough

The readAll() method in the GenericDaoJpa class was updated to modify its JPQL query, adding an explicit ORDER BY c.id clause to ensure that all returned entities are sorted by their id attribute.

Changes

File(s) Change Summary
src/main/java/ai/elimu/dao/jpa/GenericDaoJpa.java Modified the readAll() method to add ORDER BY c.id in its JPQL query.

Possibly related issues

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/main/java/ai/elimu/dao/jpa/GenericDaoJpa.java (1)

37-40: Remove redundant cast
The call to em.createQuery(..., entityClass).getResultList() already returns List<T>. The explicit cast to (List<T>) is unnecessary and can be removed to simplify the code.

- return (List<T>) em.createQuery(...).getResultList();
+ return em.createQuery(...).getResultList();
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02d24bb and 012aa34.

📒 Files selected for processing (1)
  • src/main/java/ai/elimu/dao/jpa/GenericDaoJpa.java (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: test_ui
  • GitHub Check: build (windows-latest, 17)
  • GitHub Check: build (macos-latest, 21)
  • GitHub Check: test_rest
  • GitHub Check: build (windows-latest, 21)
  • GitHub Check: test_rest
  • GitHub Check: test_rest
  • GitHub Check: build (macos-latest, 17)
  • GitHub Check: build (ubuntu-latest, 21)
  • GitHub Check: build (ubuntu-latest, 17)
  • GitHub Check: test_rest
  • GitHub Check: test_rest
🔇 Additional comments (1)
src/main/java/ai/elimu/dao/jpa/GenericDaoJpa.java (1)

37-40:

Details

✅ Verification successful

Validate JPQL entity name and id attribute
Using entityClass.getSimpleName() and hard‐coded c.id assumes your @Entity name matches the simple class name and that the primary key property is named id. This may break if you use a custom entity name (via @Entity(name="...")) or a different id field name. Consider retrieving the entity name from the JPA Metamodel or using the Criteria API for a more robust, type-safe implementation.

Example using the Metamodel:

String entityName = em.getMetamodel().entity(entityClass).getName();
return em.createQuery(
    "SELECT c FROM " + entityName + " c ORDER BY c.id", 
    entityClass
).getResultList();

Or with CriteriaBuilder:

CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<T> cq = cb.createQuery(entityClass);
Root<T> root = cq.from(entityClass);
cq.select(root).orderBy(cb.asc(root.get("id")));
return em.createQuery(cq).getResultList();

Run this script to check for any entities specifying a custom name:


🏁 Script executed:

#!/bin/bash
# Search for @Entity annotations with a name attribute
rg "@Entity\s*\(.*name\s*=" -R .

Length of output: 439


🏁 Script executed:

#!/bin/bash
# Search for @Entity annotations with a custom name attribute
rg "@Entity\s*\([^)]*name\s*=" .

# List all fields annotated with @Id to verify their property names
rg "@Id" -A1 .

Length of output: 205


🏁 Script executed:

#!/bin/bash
# Verify the field name annotated with @Id in BaseEntity.java
rg "@Id" -n src/main/java/ai/elimu/entity/BaseEntity.java -A2 -B1

Length of output: 157


No custom entity names or id properties detected—current JPQL is safe

  • rg "@Entity(…name=" returned no matches: no entities use a custom name attribute.
  • All @Id annotations point to private Long id in BaseEntity.java.

You can safely continue using

em.createQuery(
  "SELECT c FROM " + entityClass.getSimpleName() + " c ORDER BY c.id",
  entityClass
)

without breaking the existing model.

@jo-elimu jo-elimu merged commit 33a80a5 into elimu-ai:main May 30, 2025
20 checks passed
@nya-elimu
Copy link
Copy Markdown
Member

@jeevakumar-m Congrats on your first pull request contribution! 🎉

If you would like to be included in our monthly token allocations, please add yourself to contributor-addresses.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants