How do you implement a many-to-many relationship in JPA?
Map a many-to-many relationship in JPA with @ManyToMany and @JoinTable, keep both sides in sync, and know when to use a join entity instead.
2,882 posts about Java: questions with answers, tutorials and articles, newest first.
Map a many-to-many relationship in JPA with @ManyToMany and @JoinTable, keep both sides in sync, and know when to use a join entity instead.
@ManyToOne maps many rows of one entity to a single row of another through a foreign key. See how to configure it, make it lazy and avoid N+1 queries.
Learn how JPA lazy loading works, why LazyInitializationException occurs, and how to load associations with fetch joins, entity graphs or DTO projections.
Pageable carries page, size and sort into Spring Data queries. Learn PageRequest, Page versus Slice, controller binding and pagination performance tips.
Set JPA properties with spring.jpa and spring.jpa.properties in Spring Boot, and learn which popular settings, such as MySQL5Dialect, no longer work.
Practical Spring Boot caching rules: choose what to cache, bound size and TTL, design keys, evict on writes, handle cache failures and monitor hit rates.
Putting @Cacheable on a class applies caching to all its methods, but shared keys can collide. See how to use it safely and when @CacheConfig is better.
Configure Spring Boot caching with annotations, then pick Caffeine for local or Redis for shared storage and tune expiry, eviction and metrics.
CacheKeyGenerator is the JSR-107 hook that builds cache keys for @CacheResult. See how it differs from Spring's KeyGenerator, with examples.
Spring's cache abstraction has no TTL, so expiration is set in the provider. Configure Caffeine, Redis or Ehcache 3, then evict on change.
On a method, @Cacheable caches the return value by its arguments. Learn how to control keys, conditions and synchronized loading per method.
Keep caches consistent across threads, instances and database commits using sync=true, Redis, transaction-aware eviction and invalidation messages.
@CacheConfig sets shared cache names, key generator, cache manager and resolver for every cache annotation in a Spring class. See usage and pitfalls.
Set up Redis caching in Spring Boot 3 with @Cacheable, TTL, JSON serialization and per-cache expiry, plus how to survive a Redis outage.
Hazelcast backs Spring's cache abstraction with a shared in-memory cluster. See setup, map expiry, serialization and when to choose it.
Set up a shared cache across Spring Boot instances with Redis, @Cacheable and per-cache TTLs, then compare Hazelcast and learn production pitfalls.
Learn how @CacheEvict keeps Spring caches consistent: evict by key or all entries, set the timing, combine with @Cacheable and avoid proxy pitfalls.
Learn how to configure Caffeine and Redis cache managers in Spring Boot and how to write a custom CacheManager and Cache with per-cache expiry.
@Cacheable stores a method's result in a named cache so repeated calls with the same arguments return instantly without re-running the method.
Enable caching with @EnableCaching, pick a provider with spring.cache.type, and tune expiry and size through application.yml or a custom CacheManager bean.