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

Java.Hibernate.Spring.Middle.Self invocation

There is one of the most common (and subtle) pitfalls of Spring’s @Transactional: self-invocation, which can silently break transactional (and other proxy-based) behavior. 🔎 What is self-invocation? It’s when a method in a Spring bean calls another method on the … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Spring.Middle.Self invocation

Java.Hibernate.if we have transactional inside transactional how will it work ?

✅ When you call a @Transactional method from another @Transactional method in the same bean (or same Spring proxy): By default, Spring uses propagation REQUIRED, which means: The inner @Transactional method joins the existing transaction of the outer method. There’s … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.if we have transactional inside transactional how will it work ?

Java.Hibernate.Middle.Examples where batch work and where not

let’s put it all together with two clean, full examples side by side: one where batch fetching works (correct) and one where it doesn’t work (incorrect). I’ll give you them both without extra comments, so you can clearly compare. ✅ … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.Examples where batch work and where not

Java.Hibernate.Middle.What means proxies, when we speak of lazy loading?

when I say “proxies,” I do mean entities, but specifically lazy-loaded entities or collections that Hibernate wraps in a proxy object. Here’s what that means: 🔎 What is a proxy in Hibernate? A proxy is a lightweight placeholder object Hibernate … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.What means proxies, when we speak of lazy loading?

Java.Hibernate.Middle.If i load entity in first level cache and i have 2 level cache, where my entity will live?

✅ What happens when you load an entity? When you fetch an entity with Hibernate (e.g., em.find() or HQL query), the lookup happens in order: 1️⃣ First-level cache (1st-level) — also called the persistence context or session cache: Every open … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.If i load entity in first level cache and i have 2 level cache, where my entity will live?

Java.Hibernate.Middle.When batch will not work ?

🚫 1. Detached entities or closed session Batch fetching works only if multiple lazy proxies are accessed within the same persistence context (i.e., the same open Hibernate Session or JPA EntityManager). If you load entities in one transaction but access … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.When batch will not work ?

Java.Hibernate.Middle.What are batch fetching and how do you enable it?

batch fetching is a great way to avoid the N+1 problem without forcing eager loading. Let’s break it down clearly: 🔎 What is batch fetching? When you use lazy loading, Hibernate loads collections or associated entities on demand — but … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.What are batch fetching and how do you enable it?

Java.Hibernate.Middle.How do you configure fetch type for an association?

You configure the fetch type for an association directly on your entity mapping using the fetch attribute of @OneToOne, @OneToMany, @ManyToOne, or @ManyToMany. Here’s how: ✅ For @OneToOne and @ManyToOne By default, these are EAGER, but you can override: ✅ … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.How do you configure fetch type for an association?

Java.Hibernate.Middle.Dublicating parents when fetch join

🔎 The root cause: how SQL JOINs work with one-to-many Imagine you have: Author (id=1) with 3 Books (Book A, Book B, Book C). When you do a JOIN to get authors and their books: Your SQL result will look … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.Dublicating parents when fetch join

Java.Hibernate.Middle.How can you avoid the N+1 select problem?

✅ 1. Use JOIN FETCH in JPQL/HQL This is the most direct way: This forces Hibernate to fetch authors and their books in one SQL query. ✅ 2. Use EntityGraph (JPA 2.1+) If you want to avoid hard-coding fetch joins … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.How can you avoid the N+1 select problem?