🚀 Day21 – Hibernate One-to-One Mapping Today I explored One-to-One relationship in Hibernate, a fundamental concept for linking two entities directly. 🔹 What I Worked On: ✔️ Implemented One-to-One mapping using annotations ✔️ Used @OneToOne and @JoinColumn 🔗 ✔️ Connected two entities with a single relationship ✔️ Stored linked data across tables 🔹 Concept Understanding: 👉 One record in a table is linked to exactly one record in another 👉 Example: One Student → One ID Card 🔹 Workflow: ➡️ Created two entity classes ➡️ Applied @OneToOne mapping ➡️ Configured Hibernate ➡️ Saved linked objects ➡️ Verified relationship in database ✅ 🔹 Key Learnings: ✨ Clear understanding of One-to-One relationships ✨ Learned how foreign keys work in mapping ✨ Understood uni-directional vs bi-directional mapping ✨ Improved ORM design concepts 🔹 Challenges Faced: ⚡ Deciding owning side of relationship ⚡ Correct usage of @JoinColumn ⚡ Handling cascading operations 🔹 What’s Next: 🚀 Explore One-to-Many mapping 🚀 Perform CRUD with relationships 🚀 Dive deeper into fetch types #Java #Hibernate #ORM #BackendDevelopment #LearningJourney Guided by, Anand Kumar Buddarapu sir, Saketh Kallepu sir, Uppugundla Sairam sir.
More Relevant Posts
-
🚀 Day22 – Hibernate One-to-Many Mapping Today I explored One-to-Many relationships in Hibernate, a key concept for handling real-world data associations. 🔹 What I Worked On: ✔️ Implemented One-to-Many relationship using annotations ✔️ Mapped entities with @OneToMany and @ManyToOne 🔗 ✔️ Used mappedBy for bidirectional mapping ✔️ Stored related data across multiple tables 🔹 Concept Understanding: 👉 One parent can have multiple child records 👉 Example: One Department → Many Students 🔹 Workflow: ➡️ Created entity classes (Parent & Child) ➡️ Applied relationship annotations ➡️ Configured Hibernate ➡️ Saved objects with relationships ➡️ Verified data in database ✅ 🔹 Key Learnings: ✨ Understood how Hibernate manages relationships ✨ Learned difference between uni-directional & bi-directional mapping ✨ Gained clarity on foreign key handling ✨ Improved ORM design thinking 🔹 Challenges Faced: ⚡ Correctly using mappedBy ⚡ Managing cascading operations ⚡ Understanding how data is stored across tables 🔹 What’s Next: 🚀 Explore Many-to-Many relationships 🚀 Perform CRUD with relationships 🚀 Optimize fetching strategies (Lazy vs Eager) #Java #Hibernate #ORM #BackendDevelopment #FullStackDevelopment #LearningJourney Guided by, Anand Kumar Buddarapu sir, Saketh Kallepu sir, Uppugundla Sairam sir.
To view or add a comment, sign in
-
🚀 Hibernate Deep Dive – What I Learned in the Last 2 Days Over the past couple of days, I focused heavily on strengthening my understanding of Hibernate, JPA, and transaction management — not just from a coding perspective, but from an architecture and decision-making standpoint. Here are some key takeaways that helped me move from “knowing” to actually “understanding”: --- ### 🔹 Hibernate vs JPA – Clarity Matters *JPA is just a specification (rules/contract) * Hibernate is an implementation of that specification * 👉 Insight: Always code against JPA for flexibility, but understand Hibernate deeply for real-world behavior and optimizations --- ### 🔹 Transaction Management – The Backbone * Transactions ensure data consistency & atomicity * Learned how Hibernate manages transactions internally using: * `beginTransaction()` * `commit()` * `rollback()` * 👉 Key realization: Improper transaction handling = biggest production bugs --- ### 🔹 Criteria API – Type-Safe Queries * Unlike HQL, Criteria API provides type safety * Helps in building dynamic queries at runtime * 👉 Useful when query conditions are not fixed --- ### 🔹 Configuration Styles Explored different ways to configure Hibernate: * XML-based (`hibernate.cfg.xml`) * Annotation-based (`@Entity`, `@Table`) * Hybrid approach (real-world usage) 👉 Insight: Modern apps prefer annotations, but XML still appears in legacy systems --- ### 🔹 HQL (Hibernate Query Language) * Works on **objects, not tables** * Much more powerful than it initially looks * Supports joins, aggregation, and complex queries 👉 Big takeaway: HQL bridges the gap between SQL power and OOP abstraction --- ### 🔹 Inheritance Mapping in Hibernate * SINGLE_TABLE * JOINED * TABLE_PER_CLASS 👉 Learned when to use each strategy based on performance vs normalization trade-offs --- ### 🔹 Embedded vs Embeddable * `@Embeddable` → reusable value object * `@Embedded` → used inside entity 👉 Clean way to avoid duplication and improve design --- ### 🔹 Caching & Performance Awareness * First-level cache (Session level) * Understanding how Hibernate reduces DB hits --- ### 💡 Biggest Realization Learning Hibernate is not about memorizing annotations — it’s about understanding: * **How ORM bridges object world & relational world** * **When to use what (JPA vs Hibernate-specific features)** * **How architecture decisions impact performance and scalability** --- ### 💻 Practice Repository I’ve been actively implementing these concepts hands-on here: 👉 [https://lnkd.in/g5v5cmfe) ### 📌 What’s Next? * Spring Data JPA deep dive * Second-level caching * Real-world optimization scenarios 🔥 Consistency is paying off — every interview gap is becoming a learning opportunity. #Hibernate #JPA #Java #BackendDevelopment #LearningInPublic #SystemDesign #ORM
To view or add a comment, sign in
-
While debugging a Hibernate issue recently, I came across something interesting 👇 `org.hibernate.ObjectNotFoundException` — a small error with a big lesson. At first glance, it looked like a typical lazy loading problem. But the actual root cause was deeper. 🔍 What was happening? Hibernate created a proxy for a related entity, but when it tried to initialize it, the corresponding row didn’t exist in the database. 👉 In short: The application assumed data integrity, but the database told a different story. ⚠️ The tricky part? The exception wasn’t thrown during query execution. It appeared during debugging when `toString()` was triggered on a proxy object. 💡 Key learnings from this: 🔹 ORM frameworks don’t guarantee data consistency — your database does 🔹 Lazy loading can hide issues until runtime (or even debug time) 🔹 Using Lombok `@ToString` blindly on entities can backfire 🔹 Circular relationships (OneToMany ↔ ManyToOne) can lead to unexpected behavior 🛠 What helped fix it: ✔ Verifying referential integrity at the database level ✔ Avoiding unnecessary eager access during debugging ✔ Restricting `toString()` to only essential fields ✔ Using LEFT JOIN fetch where relationships may be optional 🚀 Takeaway: Most production issues are not about complex logic — they are about mismatches between your assumptions and actual data. Always trust your database more than your ORM. #Java #Hibernate #SpringBoot #BackendDevelopment #Debugging #SoftwareEngineering #Production #ProductionIssues #ErrorHandling
To view or add a comment, sign in
-
✅ Implementing CRUD Operations Using Hibernate Today I moved beyond basics and explored how Hibernate actually performs real-world database operations. ⏱️ What I Explored Today: 🔹 CRUD operations using Hibernate 🔹 Create → persist() to save objects 🔹 Read → find() / get() to fetch data 🔹 Update → merge() to modify records 🔹 Delete → remove() to delete data 🔹 Table configuration using hibernate.hbm2ddl.auto 💡 Impact on My Project: Today’s learning made my backend development more practical: ✔️ I can now perform full CRUD operations using Hibernate ✔️ I understand how to handle database operations using objects instead of SQL ✔️ I learned how to automatically create and update tables ✔️ I can build applications with less boilerplate and cleaner code ✔️ I now see how real-world systems manage data efficiently using ORM 🔥 Big Realization: Database operations don’t need to be complex… Hibernate makes it simpler, structured, and developer-friendly. Consistency is turning knowledge into real implementation #UpskillingJourney #LearningInPublic #Hibernate #ORM #CRUD #Java #BackendDevelopment #DatabaseManagement #DeveloperJourney #BuildInPublic #TechGrowth #KeepLearning #FutureReady
To view or add a comment, sign in
-
-
I recently made a seemingly small architectural change in one of my projects using Hibernate ORM and the performance improvement was not just noticeable, it was unexpected. Most developers assume “clean” relational design is always the right choice but my project proves that assumption turned out to be wrong. I replaced a classic table relationship (2 tables with back-reference, or even 3 with a join table) with a simple JSON field. Result: a surprisingly big performance boost. Why? No joins. Less complexity and Faster reads. If you’re using Hibernate, I strongly recommend checking out the JSON support from Vlad Mihalcea. It makes integration straightforward. But here’s the catch: JSON breaks easily when your model changes. You lose schema safety and old data can become unreadable. To solve this, I built a small helper tool to handle versioning and keep things stable. Here is it: https://lnkd.in/eujvVewK JSON can be a serious performance win but only if you handle evolution properly. Otherwise, you’re trading one problem for another. #Java #Hibernate #JPA #Performance #SoftwareArchitecture #Backend #DatabaseDesign #JSON
To view or add a comment, sign in
-
-
Setting every JPA relationship to FetchType.LAZY is the easy part. Living with the consequences is where most projects quietly fall apart. Here is what happens. You mark all your @ManyToOne and @OneToOne relationships as LAZY because every blog post tells you to. Your entities look clean. Then you write a service method that loads a Transaction and accesses transaction.getWorkspace().getName(). If the persistence context is still open, Hibernate silently fires a second query. If it is closed - which it will be once you disable OSIV like you should - you get a LazyInitializationException. The knee-jerk fix is to flip back to EAGER. Now every query that touches Transaction loads the Workspace too, whether the caller needs it or not. You just traded one problem for a worse one that is harder to detect. The actual solution is @EntityGraph on the repository method that needs the association: @EntityGraph(attributePaths = {"workspace", "createdByUser"}) List findByWorkspaceIdAndDateBetween(...) This tells Hibernate: for this specific query, load workspace and createdByUser in a single JOIN. Every other method on the same repository keeps lazy loading. You get per-method fetch control without touching the entity definition. The pattern I follow: entities are always LAZY. The repository method decides what to load based on the use case it serves. If a method does not access a relationship, it pays zero cost for it. If it does, the @EntityGraph makes it explicit and testable. To verify it works, I clear the persistence context in tests (entityManager.clear()), then access the relationship on the detached entity. If @EntityGraph did its job, no exception. If it did not, LazyInitializationException tells me exactly what I missed. Lazy-by-default is not a strategy. Lazy-by-default with explicit entity graphs per use case is. #SpringBoot #JPA #Hibernate #BackendDevelopment
To view or add a comment, sign in
-
🚀 Day 18 – Hibernate Today I moved beyond JDBC and started learning Hibernate, a powerful ORM (Object Relational Mapping) framework that makes database interaction in Java much easier and more efficient 💻 🔹 Understanding Hibernate: ✔ Hibernate is an ORM tool that connects Java objects with database tables ✔ It removes the need to write complex SQL queries manually ✔ Built on top of JDBC, but offers a more advanced and simplified approach 💡 Instead of dealing with SQL directly, we interact with objects → making code cleaner and easier to maintain 🔹 Core Concepts Covered: 📌 Configuration (hibernate.cfg.xml) Stores database connection details, driver info, dialect, and mapping settings 📌 SessionFactory Heavy object created once, used to generate sessions 📌 Session Acts as a link between the application and the database, used for CRUD operations 📌 Transaction Maintains data integrity using commit and rollback mechanisms 🔹 Hibernate Flow: ➡️ Configure Hibernate (XML or properties) ➡️ Build SessionFactory ➡️ Open a Session ➡️ Start Transaction ➡️ Perform operations (save/update/delete) ➡️ Commit Transaction ➡️ Close Session 🔹 Sample Code (Saving Data): Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); session.save(employee); tx.commit(); session.close(); 💡 Less code compared to JDBC → better readability and efficiency 🔹 Benefits of Hibernate: ✔ Eliminates repetitive SQL writing ✔ Supports multiple databases (DB-independent) ✔ Automatic mapping of tables and objects ✔ Reduces boilerplate code ✔ Speeds up development process 🔹 Key Takeaways: ✨ Gained clarity on ORM (Object–Table mapping) ✨ Learned Hibernate architecture and its workflow ✨ Understood differences between Hibernate and JDBC ✨ Saw how frameworks simplify backend development 🔹 Next Steps: 🚀 Implementing full CRUD operations using Hibernate 🚀 Learning annotations like @Entity, @Id, etc. 🚀 Integrating Hibernate into a real-time project Guided by, Anand Kumar Buddarapu sir.
To view or add a comment, sign in
-
-
Fixing a tricky ORA-00001 error in a Spring Boot + Hibernate application taught me an important lesson about how ORM actually works under the hood. Recently, while working on an Account Payable module, I encountered this error: ORA-00001: unique constraint (DRAFT_LEDGC_PK) violated At first glance, it looked like a simple database issue. But the real problem was deeper in the application logic. The system was updating journal entries, but instead of updating existing ledger records, Hibernate was trying to insert new ones with the same primary key. Root cause: While processing ledger entries in a loop, new entity objects were being created every time, even for records that already existed in the database. Since Hibernate treats new objects as fresh inserts, it attempted to insert duplicate primary keys, causing the failure. What fixed it: Instead of blindly creating new objects, I reused existing entities by fetching them from the parent object’s collection and matching them using the composite primary key. If a matching record was found → update it If not → create a new one Key takeaway: Hibernate doesn’t magically know your intent. If you create a new object, it will try to INSERT. If you want UPDATE, you must work with an existing managed entity. This small change fixed the issue and made the update flow much more reliable. Sometimes, the bug is not in the query or database — it's in how we manage entity state. #SpringBoot #Hibernate #Java #BackendDevelopment #Debugging #Learning #Tech
To view or add a comment, sign in
-
Day 29. I enabled query logging for the first time. What I saw surprised me. I had this: List<User> users = userRepository.findAll(); Simple. Clean. One line. I assumed Hibernate was handling it efficiently. Then I added this: spring.jpa.show-sql=true And watched the logs. Not one query. Multiple hidden ones. → Fetch users → Then fetch relationships → Then more queries behind the scenes Hibernate wasn’t optimizing anything. It was executing exactly what I told it to — lazily, one relationship at a time. That’s when it clicked. ORM doesn’t optimize your queries. It executes what you tell it to. (see fix below 👇) Or better: 👉 Fetch only what you need (DTO projection) What I learned: → Hibernate is not magic → Default behavior is not always efficient → You are responsible for query performance The hard truth: → “It works” doesn’t mean “it’s optimized” → ORM hides complexity — it doesn’t remove it Writing code that runs is easy. Understanding what your database is actually doing is what makes you a backend developer. Have you ever checked your query logs and been surprised? 👇 Drop your experience #SpringBoot #Java #Hibernate #BackendDevelopment #Performance #JavaDeveloper
To view or add a comment, sign in
-
-
🚀 2 Weeks Learning Update – Hibernate & ORM Journey Over the past 2 weeks, I focused on strengthening my fundamentals of Hibernate and ORM concepts through practical learning 📚 What I Covered: 🔹 ORM (Object Relational Mapping) Learned how Hibernate maps Java objects to database tables, reducing the need for complex SQL. 🔹 Hibernate Architecture Understood key components like Session, SessionFactory, and how Hibernate manages data internally. 🔹 CRUD Operations Performed Create, Read, Update, and Delete operations using Hibernate. 🔹 Fetching Strategies ✔️ Lazy Loading vs Eager Loading Learned how data is fetched and its impact on performance. 🔹 Caching ✔️ Level 1 Cache (Session-level) ✔️ Level 2 Cache (SessionFactory-level) 🔹 Annotations ✔️ @GeneratedValue for automatic ID generation 🔹 Entity Relationships (Associations) ✔️ One-to-One ✔️ One-to-Many ✔️ Many-to-One ✔️ Many-to-Many 🔹 LOB Data Types ✔️ BLOB (Binary Large Object) ✔️ CLOB (Character Large Object) 🔹 HQL / JPQL Learned how to perform CRUD operations using object-oriented queries instead of SQL. 👉 These query languages are similar to SQL but work with objects instead of tables 💻 Project Link: 🔗 https://lnkd.in/gJGRzj7A 🎯 Key Takeaway: Hibernate simplifies database interaction by handling mapping, queries, and caching — making backend development more efficient and clean. 💭 My Thought: Understanding Hibernate deeply is helping me build a strong foundation for Spring Boot and real-world backend development 🚀 Consistency is everything — learning step by step 💪 #Hibernate #ORM #JavaDeveloper #BackendDevelopment #LearningJourney #SpringBoot #JPA #CodingLife #FutureEngineer
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