This document provides an overview of several Java technologies:
- JPA Auditing for tracking entity creation/modification dates and users
- Domain Events in DDD for triggering processing across aggregates
- javax.validation for validating entities before database writes
- Spring Data Repos for implementing repositories with query methods and custom logic
It also briefly discusses JPA auditing implementation, domain event publishing, custom validators, and the @NonNullApi annotation for preventing null returns from repositories.
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
Hibernate and Spring - Unleash the Magic
1.
2. Victor Rentea
VictorRentea.ro
Recorded Talks, Blog, Video Courses, ...
Independent Trainer
Founder of
Bucharest Software Craftsmanship Community
Java Champion
❤️ Simple Design, Refactoring, Unit Testing ❤️
3. Training
500 days
(200+ online)
2000 devs
8 years 50+ companies
Reach out
to me:
Hibernate
Spring Func Prog
Java Performance
Reactive Prog
Design Patterns
Pragmatic DDD
Clean Code
Refactoring
Unit Testing
TDD
@victorrentea
Intense
Video Courses: victorrentea.teachable.com
More: VictorRentea.ro
6. Get Set ....
• JPA Auditing
• Domain Events
• javax.validation
• Spring Data Repos
7. JPA Auditing
• @CreatedBy / Date
• @LastModifiedBy / Date
• Relies on @PrePersist, @PreUpdate JPA Hooks defined via
• @EntityListeners on @Entity or
• global via orm.xml
• User is retrieved from an AuditorAware
• Typically from Spring Security Session (SecurityContextHolder)
8. Domain Events (DDD)
• Problem: logic inside an @Entity methods needs to trigger further
processing, involving other unrelated Aggregates
• At .save(e), the Entity is scanned for a @DomainEvents getter
• Pitfall: What if I forget to .save()?
• Pitfall: Auto-flushing the dirty entity does NOT publish the events
➔Alternative: static EventPublisherHolder
• Events are delivered to all interested @EventListener
• In the same transaction (default, safest)
• After the current transaction COMMITS - @TransactionalEventListener
9. javax.validation
• Before writing to DB, @Entities are automatically validated:
• @NotNull
• @Size(min=)
• @Pattern(regexp=)
• ...
• Custom Validators (even loaded from Spring)
10. CustomerRepository
Customer findByName(String name);
@Query("SELECT c FROM Cust... ")
List<Customer> getActiveCustomers();
JpaRepository<E,ID>
List<E> findAll();
E findOne(ID);
void save(E);
void delete(E); ...
CustomerRepositoryCustom
List<Customer> search(CustomerSearch);
CustomerRepositoryImpl
List<Customer> search(CustomerSearch) {
...<implem>...
}
CustomBaseRepository<E,ID>
E findExactlyOne(ID id);
CustomBase
RepositoryImpl
<implem>
naming
convention
Spring Data Repo Architecture
JpaSpecificationExecutor<E>
List<E> findAll(Specification<E> spec);
QuerydslPredicateExecutor<E>
List<E> findAll(Predicate spec);
Codegeneration
via
Maven Plugin