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

Java.Hibernate.Middle.What is the N+1 select problem in Hibernate?

🔎 What is the N+1 select problem? It happens when you fetch a collection of parent entities, and then Hibernate lazily loads each child entity in a separate query. Specifically:1️⃣ First, Hibernate executes 1 query to load your list of … Continue reading →

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

Java.Hibernate.Middle.How do you monitor cache hit/miss statistics?

✅ Short Answer You can monitor Hibernate’s second-level cache statistics using the Hibernate Statistics API, which tracks cache hits, misses, and puts for entities, collections, and queries. 🔎 Detailed Explanation 🔹 1) Enable Hibernate StatisticsFirst, you must enable statistics collection … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.How do you monitor cache hit/miss statistics?

Java.Hibernate.Medium.How can i evict entity from Hibernate Cache in Spring enviroment ?

✅ Short Answer In a Spring environment, you evict an entity from the second-level cache by accessing the SessionFactory bean (from your JPA/Hibernate integration) and calling getCache().evictEntityData(…). 🔎 Detailed Explanation 🔹 1) Obtain the SessionFactoryIf you use Spring Boot with … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Medium.How can i evict entity from Hibernate Cache in Spring enviroment ?

Java.Hibernate.Middle.How do you evict an entity from the second-level cache?

✅ Short Answer You can evict a specific entity or entire cache regions from Hibernate’s second-level cache using the SessionFactory.getCache() API → this lets you remove stale or invalid entries manually. 🔎 Detailed Explanation 🔹 1) Evict a Specific EntityTo … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.How do you evict an entity from the second-level cache?

Java.Hibernate.Medium.How can you cache query results?

✅ Short Answer You can cache query results in Hibernate by:1️⃣ Enabling the query cache in your Hibernate configuration.2️⃣ Marking individual queries as cacheable with .setCacheable(true).This allows Hibernate to store entire result sets in the second-level cache, speeding up repeated … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Medium.How can you cache query results?

Java.Hibernate.Middle.How Hibernate invalidates cache in case of read-write strategy ?

✅ Short Answer In READ_WRITE strategy, Hibernate uses a mechanism called cache invalidation: when an entity is updated or deleted, it evicts the corresponding cached entry, marking it stale so it can’t be served until reloaded from the database. 🔎 … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.How Hibernate invalidates cache in case of read-write strategy ?

Java.Hibernate.Middle.What is the difference between read-only and read-write second-level cache strategies?

✅ Short Answer READ_ONLY strategy: for immutable data — assumes entities never change → highest performance but unsafe if data is updated. READ_WRITE strategy: for mutable data — safely tracks changes and synchronizes the cache when entities are updated → … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Middle.What is the difference between read-only and read-write second-level cache strategies?

Java.Hibernate.Medium.when do i need 2 level cache ?

✅ Short Answer You need a second-level cache (2LC) when your application frequently reads the same data across sessions and wants to avoid repeated database hits, especially for read-heavy, rarely changing data. 🔎 Detailed Explanation 🔹 When 2LC is useful✅ … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Medium.when do i need 2 level cache ?

Java.Hibernate.Medium.How do you configure second-level cache with Ehcache or another provider?

✅ Short Answer To configure Hibernate’s second-level cache with Ehcache (or another provider), you:1️⃣ Add the caching library to your dependencies.2️⃣ Configure Hibernate properties to enable second-level and query caches.3️⃣ Configure your cache provider (Ehcache or others) via XML or … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Medium.How do you configure second-level cache with Ehcache or another provider?

Java.Hibernate.Medium.What are pros and cons of each inheritance mapping strategy?

✅ 1) SINGLE_TABLE Pros:✅ Fastest read performance → only one table, no joins or unions needed.✅ Simpler to query → easy polymorphic queries.✅ Simple schema → easier to manage in simple hierarchies. Cons:❌ Many nullable columns → wasted space when … Continue reading →

Posted in Без рубрики | Comments Off on Java.Hibernate.Medium.What are pros and cons of each inheritance mapping strategy?