Category Archives: Без рубрики

Java.Hibernate.Middle.What is the difference between @OneToMany(mappedBy=…) vs. @JoinColumn?

✅ Short Answer @OneToMany(mappedBy=…) marks the inverse side of a bidirectional relationship → it tells JPA the parent does not own the foreign key. @JoinColumn marks the owning side → it defines where the foreign key is stored in the … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.What is the difference between @OneToMany(mappedBy=…) vs. @JoinColumn?

Java.Hibernate.Middle.How do you map an embeddable object in Hibernate?

✅ Short Answer In Hibernate/JPA, you map an embeddable object using @Embeddable on the value class, and @Embedded on the owning entity’s field → the embeddable’s fields become columns in the entity’s table. 🔎 Detailed Explanation 🔹 Embeddables are reusable … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.How do you map an embeddable object in Hibernate?

Java.Hibernate.Middle.How do you map a many-to-many relationship with extra columns?

✅ Short Answer To map a many-to-many relationship with extra columns in the join table, you can’t use plain @ManyToMany.Instead, you must model the join table as a separate entity with two @ManyToOne relationships — this is called an association … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.How do you map a many-to-many relationship with extra columns?

Java.Hibernate.Middle.What means orphan removal ? Give example

✅ Short Answer Orphan removal means that if you remove a child entity from its parent’s collection, JPA will automatically delete that child entity from the database, treating it as an “orphan.” 🔎 Detailed Explanation 🔹 By default in a … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.What means orphan removal ? Give example

Java.Hibernate.Middle.What sql’s are executed when i select, insert, delete parent/child, especially when i need bidirectional connections ?

✅ Scenario: Mapping You have: 📥 Insert Parent + Children Code: SQL executed:1️⃣ INSERT parent row: 2️⃣ INSERT each child row with foreign key: 📤 Select Parent + Children Parent alone: SQL: ✅ No child data loaded if collection is … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.What sql’s are executed when i select, insert, delete parent/child, especially when i need bidirectional connections ?

Java.Hibernate.Middle.How do you map a bidirectional one-to-many relationship?

✅ Short Answer To map a bidirectional one-to-many relationship, you:1️⃣ Add a @OneToMany(mappedBy = “…”) collection on the parent side.2️⃣ Add a @ManyToOne reference to the parent on the child side.This creates a two-way link between parent and child entities. … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.How do you map a bidirectional one-to-many relationship?

Java.Hibernate.Middle.How do you map a unidirectional one-to-many relationship?

✅ Short Answer To map a unidirectional one-to-many relationship, you use @OneToMany on the “one” side without a corresponding mapping on the “many” side. You typically combine it with @JoinColumn to specify the foreign key column in the “many” table. … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.How do you map a unidirectional one-to-many relationship?

Java.Hibernate.Middle.When to use which instrument to solve n+1 problem ?

✅ Use JOIN FETCH when: You always need the associated data in that query’s result (e.g., displaying authors and their books in a UI table). You’re only fetching one collection or single-valued associations → avoids Cartesian explosion. You want maximum … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.When to use which instrument to solve n+1 problem ?

Java.Hibernate.Middle.Give me a full list of decisions of n + 1 problem

✅ 1) Join fetches (JOIN FETCH in JPQL/HQL) Load parent and associated entities in one SQL query. Example: Pros: very effective; simple. Cons: can cause Cartesian product explosions when fetching multiple collections. ✅ 2) Entity graphs (EntityGraph API) Declaratively specify … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.Give me a full list of decisions of n + 1 problem

Java.Hibernate.Medium.What is subselect fetching?

🔎 What is subselect fetching? Subselect fetching is a Hibernate-specific fetch strategy for collections (e.g., @OneToMany, @ManyToMany) that reduces the N+1 select problem in a different way than batch or join fetches. Instead of: executing N separate queries (1 per … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Medium.What is subselect fetching?