Hackforge Academy

Category: java

jpa query like delete sort

Published on 19 May 2026

Explanation

Update query in JPA requires @Modifying and @Transactional annotations.

Code:

@Modifying
@Transactional
@Query("UPDATE User u SET u.name = :name
 WHERE u.id = :id")
void updateName(@Param("id") Long id, 
@Param("name") String name);

Explanation

Delete query removes records from the database using JPQL.

Code:

@Modifying
@Transactional
@Query("DELETE FROM User u WHERE u.id = :id")
void deleteUser(@Param("id") Long id);

Explanation

Sorting can be done using ORDER BY in JPQL query.

Code:

@Query("SELECT u FROM User u ORDER BY u.name ASC")
List<User> getUsersSorted();

Explanation

LIKE operator is used for searching records with partial matching.

Code:

@Query("SELECT u FROM User u WHERE u.name LIKE %:keyword%")
List<User> searchUsers(@Param("keyword") String keyword);

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community