Skip to content
javabypankaj
HomeLibraryPopularCommunity
09
JPA & Hibernate
17 topics · 69 questions
1JPA Fundamentals0/552N+1 Problem & Fetching0/223Entity Mapping: Relationships0/54Entity Mapping: Keys, Columns & Annotations0/885Embeddable, Inheritance & Secondary Tables0/556Spring Data Repositories0/447Queries: JPQL, Native, Derived, Criteria0/668Projections: Interface, DTO, Dynamic0/449Entity Lifecycle & Auditing0/2210Locking: Optimistic & Pessimistic0/4411Pagination & Sorting0/3312Performance: Large IN, Dirty Checking, OSIV0/6613Flush, Persist & Cache0/5514Cascade, Orphan Removal & Soft Delete0/2215Batch Processing0/2216Multi-Database & Migration0/2217Scheduling: @Scheduled, ShedLock, Retry0/44
1JPA Fundamentals52N+1 Problem & Fetching23Entity Mapping: Relationships54Entity Mapping: Keys, Columns & Annotations85Embeddable, Inheritance & Secondary Tables56Spring Data Repositories47Queries: JPQL, Native, Derived, Criteria68Projections: Interface, DTO, Dynamic49Entity Lifecycle & Auditing210Locking: Optimistic & Pessimistic411Pagination & Sorting312Performance: Large IN, Dirty Checking, OSIV613Flush, Persist & Cache514Cascade, Orphan Removal & Soft Delete215Batch Processing216Multi-Database & Migration217Scheduling: @Scheduled, ShedLock, Retry4
17 topics69 Qs0%
01Core Java17002OOP3203Collections6704Exception Handling2805Concurrency & Multithreading12706Java Streams, Lambda & Functional Programming32807Spring & Spring Boot2608Transactions3209JPA & Hibernate6910Microservices19411Kafka & Messaging9112DevOps, CI/CD & Tooling13313Database & SQL14114REST API & Web4015Design Patterns & LLD5716Advanced Java7117Coding Problems: DSA49218AWS & Cloud4119Data Engineering19420QA, Testing & SDET4121System Design3522Security2023Behavioral / HR: STAR Method37
17Topics
69Questions
0%Complete
3 of 17 topics
Topics
1JPA Fundamentals0/552N+1 Problem & Fetching0/22
3Entity Mapping: Relationships0/55
4Entity Mapping: Keys, Columns & Annotations0/885Embeddable, Inheritance & Secondary Tables0/556Spring Data Repositories0/447Queries: JPQL, Native, Derived, Criteria0/668Projections: Interface, DTO, Dynamic0/449Entity Lifecycle & Auditing0/2210Locking: Optimistic & Pessimistic0/4411Pagination & Sorting0/3312Performance: Large IN, Dirty Checking, OSIV0/6613Flush, Persist & Cache0/5514Cascade, Orphan Removal & Soft Delete0/2215Batch Processing0/2216Multi-Database & Migration0/2217Scheduling: @Scheduled, ShedLock, Retry0/44

Entity Mapping: Relationships

JPA & Hibernate·Topic 3 of 17·5 questions
Q1How do you connect two tables with @OneToMany?

@ManyToOne on the child with @JoinColumn is the owning side that controls the FK; @OneToMany(mappedBy) on the parent is the inverse side for navigation only – always set both sides with helper methods.

Read Answer
Q2What is @OneToMany / @ManyToOne / @JoinColumn / mappedBy?

The MANY side with @ManyToOne @JoinColumn owns the foreign key; the ONE side with @OneToMany(mappedBy=...) is the inverse, and mappedBy names the owning field on the child, not a column.

Read Answer
Q3User-Order @OneToMany: a complete worked example

Order is the owning side (@ManyToOne @JoinColumn(user_id)); User is the inverse side (@OneToMany(mappedBy="user")); use cascade + orphanRemoval for a true aggregate and JOIN FETCH to avoid N+1.

Read Answer
Q4What are JPA cascade types?

Cascade propagates parent operations (PERSIST/MERGE/REMOVE/DETACH/REFRESH, or ALL) to children; orphanRemoval deletes a child when it leaves the parent's collection.

Read Answer
Q5Why must you synchronize both sides of a bidirectional relationship?

Only the owning side (the foreign key) is persisted; update both sides via helper methods so the in-memory object graph stays consistent with the database.

Read Answer
Previous · Topic 2N+1 Problem & Fetching2 questionsNext · Topic 4Entity Mapping: Keys, Columns & Annotations8 questions
javabypankaj© 2026 javabypankaj
PrivacyTerms
HomeSearchLibrary