How do you implement lifecycle callbacks in JPA?
JPA lifecycle callbacks run methods before or after an entity is persisted, updated, removed or loaded. Learn the seven annotations, listeners and their limits.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
JPA lifecycle callbacks run methods before or after an entity is persisted, updated, removed or loaded. Learn the seven annotations, listeners and their limits.
@EntityListeners links listener classes to JPA lifecycle events. See the callback signatures, execution order and rules for what callbacks may do.
Learn to call methods through the Java Reflection API, handle static, private and varargs cases, unwrap exceptions and know when MethodHandle is better.
Reflection is slower than direct calls due to lookups, boxing and lost inlining. Learn how to cache, use MethodHandle, and measure the real cost with JMH.
Get a Class object with a literal, getClass or Class.forName, then inspect its fields, methods, constructors and annotations with java.lang.reflect.
Reflection lets Java programs inspect and call classes, methods and fields at runtime. Learn its purpose, examples, performance cost and module limits.
What @Component does in Spring, how component scanning finds beans, how to inject them, and how it compares with @Service, @Repository and @Bean.
Put @PropertySource on a @Configuration class to add a properties file to the Spring Environment, then read values with @Value, Environment or @ConfigurationProperties.
ApplicationContextInitializer lets you customise the Spring context before beans are created. See where it fits, how to register it and alternatives.
Use @PostConstruct, @PreDestroy, @Bean initMethod and destroyMethod, or SmartLifecycle to run custom logic when Spring creates and destroys a bean.
@Lazy defers Spring bean creation until first use. See where to place it, how lazy injection proxies work, and the trade-offs of lazy initialization.
Define Spring prototype beans, avoid the singleton-injection trap with ObjectProvider or @Lookup, and understand why destroy callbacks do not run.
@Scope controls the lifecycle and visibility of a Spring bean. See the built-in scopes, scoped proxies and how to inject short-lived beans into singletons.
Spring beans are singletons by default. See how to define one with stereotype annotations or @Bean, verify it, and keep it thread safe.
@Bean registers the return value of a method as a Spring bean. Learn when to use it instead of @Component, plus naming, scope, and lifecycle options.
Use Spring WebClient to call REST APIs without blocking. Covers requests, error handling, timeouts, retries, filters and how it compares to RestClient.
WebClient is Spring's non-blocking, reactive HTTP client. Learn how to configure it, handle errors and timeouts, and how it compares with RestTemplate and RestClient.
Stream real-time updates from Spring WebFlux with a Flux and ServerSentEvent, broadcast to many clients and keep connections alive.
In Spring WebFlux, RouterFunction maps requests to non-blocking handlers using predicates. See a full example, the predicates and how to test it.
Set up Spring WebFlux in a Spring Boot app with the reactive starter, controllers returning Mono and Flux, WebClient and WebTestClient tests.