Modified GenericDaoJpa.java to sort readAll by id#2203
Modified GenericDaoJpa.java to sort readAll by id#2203jo-elimu merged 1 commit intoelimu-ai:mainfrom
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. 🚀 New features to boost your workflow:
|
WalkthroughThe Changes
Possibly related issues
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/main/java/ai/elimu/dao/jpa/GenericDaoJpa.java (1)
37-40: Remove redundant cast
The call toem.createQuery(..., entityClass).getResultList()already returnsList<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
📒 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
UsingentityClass.getSimpleName()and hard‐codedc.idassumes your@Entityname matches the simple class name and that the primary key property is namedid. 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 -B1Length 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 customnameattribute.- All
@Idannotations point toprivate Long idinBaseEntity.java.You can safely continue using
em.createQuery( "SELECT c FROM " + entityClass.getSimpleName() + " c ORDER BY c.id", entityClass )without breaking the existing model.
|
@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 |
Issue Number
Purpose
Technical Details
Testing Instructions
Screenshots
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:applyto fix them.