When converting between Java objects — such as entities, DTOs, or database objects — developers often rely on Jackson’s ObjectMapper for its convenience and flexibility. However, subtle differences in https://lnkd.in/dTgK9kKH
Yellow! GNU’s Post
More Relevant Posts
-
Java Performance Tip 🚀 Dealing with large datasets in Spring Data JPA? Stop loading everything into memory! Use Stream-based queries with proper fetch size configuration for better memory management and performance. ✅ Old way: Loads entire result set into memory - potential OutOfMemoryError ✅ New way: Streams data in batches - efficient memory usage and better performance Key Benefits: 🎯 Prevents OutOfMemoryError with large datasets ⚡ Processes data in chunks (batch of 1000 records) 💾 Lower memory footprint 🔄 Works seamlessly with Java Streams API 📊 Perfect for data processing and reporting Pro Tips: Always close streams properly (use try-with-resources) Use @Transactional(readOnly = true) on service methods #Java #SpringBoot #SpringData #JPA #Hibernate #Performance #BestPractices #CleanCode #SoftwareDevelopment #BackendDevelopment #TechTips
To view or add a comment, sign in
-
-
🔥 When we run a JPA query, Hibernate does a dirty check on every entity it loads to see if we changed anything. But if we are just reading data, that’s wasted work. @QueryHints(@QueryHint(name = "org.hibernate.readOnly", value = "true")) - Hibernate skips dirty checking. - Less memory, fewer CPU cycles. Use it for all read-only queries dashboards, reports, or exports. Connect Sabari Balaji for Tech Insights 💡
To view or add a comment, sign in
-
-
Recently, I was troubleshooting a Java application(Servlet) where a few SQL queries were taking unusually long to execute. At first, it looked like a database issue — but digging deeper, I noticed something interesting 👀 During those heavy query executions, the JVM memory usage was spiking, and GC (Garbage Collection) was running frequently, slowing things down even more. After some profiling and monitoring, we realized that the default heap settings were too low for our workload. So we adjusted our system configuration The result? ✅ SQL executions became much more stable ✅ Noticeable improvement in overall performance This reminded me how small JVM-level configurations can make a big difference — especially in data-heavy services. Performance tuning isn’t just about optimizing code or queries; sometimes, it’s about understanding how your application and JVM handle memory under load. #SpringBoot #Java #PerformanceTuning #BackendDevelopment #MemoryManagement
To view or add a comment, sign in
-
Avoiding JPA/Hibernate Pitfalls and Implementing Fixes 🧰 - To tackle N+1 queries, opt for fetch joins or entity graphs over separate queries. 🕸️ - Refrain from lazy-loading in controllers; instead, map to DTOs within the service layer. 🧭 - For bypassing the 1st-level cache during bulk updates, ensure to clear the context. 🧹 - Address hot rows by incorporating @Version for optimistic locking. 🔒 - When dealing with paging, prioritize stable sorting, accurate counting, and steer clear of fetch-join operations during pagination. 📑 - Enhance performance with batch inserts by configuring hibernate.jdbc.batch_size and executing flush/clear operations. 📦 - Implement auditing using Envers or explicit outbox tables. 🧾 - Profiling SQL queries is essential; avoid blind optimization strategies. 🔎 Remember, always stay vigilant and proactive in your SQL profiling efforts for optimal performance. #JPA #Hibernate #SpringData #SQL #Java
To view or add a comment, sign in
-
✅ 1. Implements the List Interface ArrayList directly implements the List interface, meaning it follows all List rules — ordered elements, index access, and support for duplicates. ✅ 2. Maintains Insertion Order Just like every List-based structure, ArrayList preserves the order in which elements are added. ✅ 3. Supports Random Access ArrayList offers fast .get() and .set() operations using index-based access. ✅ 4. Allows Duplicate Elements Since it belongs to the List family, it permits duplicates — unlike Sets. ✅ 5. Dynamic in Size ArrayList grows and shrinks automatically, overcoming the fixed-size limitation of arrays. ✅ 6. Part of the Collection Hierarchy Its place in the Java Collections Framework clearly tags it as a List-type data structure.
To view or add a comment, sign in
-
-
Difference Between flush() and commit() in JPA Understanding how JPA writes data to the database is crucial for debugging and performance tuning. Two terms often confused are flush and commit - but they work very differently. 1. What is flush()? flush() pushes the changes from the persistence context (Hibernate’s in-memory cache) to the database temporarily. > SQL statements are executed > But the transaction is not completed > Data is still rollback-able 2. What is commit()? commit() ends the transaction and makes all changes permanent. > Executes a flush internally > Finalizes and saves data > Cannot be rolled back after commit Key Difference: Flush = sync with DB (temporary) Commit = finalize transaction (permanent) #SpringBoot #JPA #Hibernate #Java
To view or add a comment, sign in
-
-
Understanding @Modifying Annotation in Spring Data JPA By default, JPA queries are read-only. But what if you need to update or delete data using a custom query? That’s where the @Modifying annotation comes in. Key points: > Use @Modifying with @Query to execute INSERT, UPDATE, or DELETE operations. > Return type can be int or void. > Must be used inside a transaction (@Transactional), otherwise changes won’t persist. 📍Tip: Always be careful these queries skip entity-level lifecycle events and directly modify the database. #SpringBoot #JPA #Hibernate #Java
To view or add a comment, sign in
-
-
𝗤𝗔: 𝗪𝗵𝗲𝗻 𝘁𝗼 𝘂𝘀𝗲 𝘀𝗮𝘃𝗲𝗔𝗻𝗱𝗙𝗹𝘂𝘀𝗵() 𝗶𝗻𝘀𝘁𝗲𝗮𝗱 𝗼𝗳 𝘀𝗮𝘃𝗲() 𝗶𝗻 𝗝𝗣𝗔? ⚙️ 𝟭. 𝘀𝗮𝘃𝗲(𝗲𝗻𝘁𝗶𝘁𝘆) ➤ Persists or updates the entity in the persistence context (the 1st-level cache of Hibernate). The change is not immediately written to the database — it’s deferred until: The transaction commits, or The persistence context is explicitly flushed. 𝘜𝘴𝘦𝘳 𝘶𝘴𝘦𝘳 = 𝘯𝘦𝘸 𝘜𝘴𝘦𝘳("𝘈𝘭𝘪𝘤𝘦"); 𝘶𝘴𝘦𝘳𝘙𝘦𝘱𝘰𝘴𝘪𝘵𝘰𝘳𝘺.𝘴𝘢𝘷𝘦(𝘶𝘴𝘦𝘳); // ✅ 𝘱𝘦𝘳𝘴𝘪𝘴𝘵𝘦𝘥 𝘪𝘯 𝘮𝘦𝘮𝘰𝘳𝘺, 𝘯𝘰𝘵 𝘺𝘦𝘵 𝘪𝘯 𝘋𝘉 // 𝘋𝘉 𝘸𝘳𝘪𝘵𝘦 𝘩𝘢𝘱𝘱𝘦𝘯𝘴 𝘭𝘢𝘵𝘦𝘳 — 𝘢𝘵 𝘤𝘰𝘮𝘮𝘪𝘵 𝘰𝘳 𝘧𝘭𝘶𝘴𝘩 ➤ 𝗪𝗵𝗲𝗻 𝘁𝗼 𝘂𝘀𝗲 Use it in most cases — it’s faster and allows Hibernate to batch SQL writes efficiently. ⚙️ 𝟮. 𝘀𝗮𝘃𝗲𝗔𝗻𝗱𝗙𝗹𝘂𝘀𝗵(𝗲𝗻𝘁𝗶𝘁𝘆) ➤ Calls save() and then immediately calls flush() on the EntityManager. This forces Hibernate to: Synchronize the persistence context with the database right now. Execute the SQL INSERT or UPDATE immediately. 𝘜𝘴𝘦𝘳 𝘶𝘴𝘦𝘳 = 𝘯𝘦𝘸 𝘜𝘴𝘦𝘳("𝘉𝘰𝘣"); 𝘶𝘴𝘦𝘳𝘙𝘦𝘱𝘰𝘴𝘪𝘵𝘰𝘳𝘺.𝘴𝘢𝘷𝘦𝘈𝘯𝘥𝘍𝘭𝘶𝘴𝘩(𝘶𝘴𝘦𝘳); // ✅ 𝘧𝘰𝘳𝘤𝘦𝘴 𝘚𝘘𝘓 𝘸𝘳𝘪𝘵𝘦 𝘪𝘮𝘮𝘦𝘥𝘪𝘢𝘵𝘦𝘭𝘺 ➤ 𝗪𝗵𝗲𝗻 𝘁𝗼 𝘂𝘀𝗲 You need the entity in the DB immediately — for example: You want to run a native query right after save. You must ensure database constraints (unique keys, triggers) are applied now. You’re debugging and want to see changes applied instantly. You’re inside a long transaction but need this part committed to DB earlier. #𝗷𝗽𝗮#𝗷𝗮𝘃𝗮
To view or add a comment, sign in
-
The Object-Oriented Way to Query Data If you’ve used JPA or Hibernate, you’ve probably heard of JPQL - the Java Persistence Query Language. It’s like SQL, but instead of querying tables and columns, you query Java objects (entities) and their fields. This makes your queries database-independent and aligned with your domain model. Example :- @Query("SELECT e FROM Employee e WHERE e.department = :dept") List<Employee> findByDepartment(@Param("dept") String department); Here’s what’s happening: Employee is an entity class, not a table name. department is a field in the Employee class, not a column. JPQL automatically translates this into SQL like: SELECT * FROM employees WHERE department = 'IT'; So instead of thinking in terms of tables, you think in terms of objects - much more natural for Java developers. Once you master JPQL, you’ll rarely need to write raw SQL again — and your code stays portable, readable, and easy to maintain. #Java #JPA #Hibernate
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development