Q1
Why does Spring @Transactional silently fail to roll back when calling another @Transactional method inside the same class (this.saveChild())?
Spring implements @Transactional via dynamic AOP proxies wrapping the bean externally. Internal this.method() calls bypass the proxy completely—no transaction boundary or rollback interceptor executes!
Q2
Why does Spring @Transactional NOT roll back on checked exceptions (IOException) by default?
Spring rolls back automatically only on unchecked RuntimeException and Error. Checked exceptions commit the partial transaction unless you explicitly add @Transactional(rollbackFor = Exception.class).
Q3
What causes Hibernate's LazyInitializationException in REST controllers when returning JPA entities directly?
Once the service transaction ends, the Hibernate Session closes before Jackson serializes lazy @OneToMany collections—throwing an exception. Always map entities into explicit response DTOs inside the service transaction or use JOIN FETCH.
Q4
How do you resolve the JPA N+1 query problem without causing Cartesian multiplication across multiple collections?
Fetching two @OneToMany bags in one JOIN FETCH throws MultipleBagFetchException or explodes row counts. Use @EntityGraph / batch size (@BatchSize), separate queries inside one transaction, or projection DTOs.
Q5
What happens if an @Entity uses Lombok @Data with bidirectional @OneToMany relationships?
@Data generates equals, hashCode, and toString across lazy associations—causing infinite mutual recursion (StackOverflowError) or broken HashSet behavior when JPA mutates generated IDs after persist.
Q6
Why is constructor injection preferred over @Autowired field injection in Spring Boot?
Constructor injection allows final immutable dependencies, makes missing dependencies fail visibly in unit tests without needing Spring context reflection, and exposes circular dependencies immediately.
Q7
What happens in Spring Security when custom JWT filters forget SecurityContextHolder.clearContext() or fail cleanly?
If thread-local security context leaks across pooled servlet threads or skips stateless session policy (SessionCreationPolicy.STATELESS), users can inherit wrong session state or unnecessary JSESSIONID cookies.
Q8
Why does @SpringBootTest slow down CI suites, and what lighter slice annotations should replace it?
@SpringBootTest boots the entire application context, DB, and beans. Use @WebMvcTest for controller/validation tests and @DataJpaTest for repository query checks.
Q9
How does ResponseEntityExceptionHandler + @RestControllerAdvice centralize clean API validation responses?
Instead of scattering try/catch blocks across controllers, @RestControllerAdvice intercepts MethodArgumentNotValidException and domain exceptions globally into consistent HTTP status codes and RFC error payloads.
Q10
When deploying Spring Boot inside Docker, why can JVM memory exceed the container limit and trigger OOMKill (Exit Code 137)?
Heap (-Xmx) is only part of JVM memory—Metaspace, thread stacks, and direct off-heap buffers add overhead. Configure -XX:MaxRAMPercentage=75.0 rather than assuming heap equals container RAM.