package Ġat . rech ner her z . example . config Ċ Ċ import Ġat . rech ner her z . example . Application Ċ import Ġat . rech ner her z . example . domain . account . Account Ċ import Ġat . rech ner her z . example . domain . account . Account Repository Ċ import Ġat . rech ner her z . example . domain . base . Internal Repository Impl Ċ import Ġorg . springframework . context . annotation . Bean Ċ import Ġorg . springframework . context . annotation . Configuration Ċ import Ġorg . springframework . data . annotation . CreatedBy Ċ import Ġorg . springframework . data . annotation . Created Date Ċ import Ġorg . springframework . data . annotation . LastModified By Ċ import Ġorg . springframework . data . annotation . Last ModifiedDate Ċ import Ġorg . springframework . data . domain . Aud itor Aware Ċ import Ġorg . springframework . data . jpa . domain . support . Audit ing Entity Listener Ċ import Ġorg . springframework . data . jpa . repository . config . Enable Jpa Audit ing Ċ import Ġorg . springframework . data . jpa . repository . config . Enable Jpa Repositories Ċ import Ġorg . springframework . transaction . annotation . Enable Transaction Management Ċ import Ġjava . util .* Ċ Ċ const Ġval ĠTRAN SACTION _ AD VICE _ ORDER Ġ= Ġ 0 Ċ Ċ /** Ċ Ġ* ĠSpring ĠData ĠJ PA Ġconfiguration . Ċ Ġ* Ċ Ġ* Ġ[ Enable Jpa Repositories . repository Base Class ] Ġsets Ġthe Ġcustomized Ġbase Ġrepository Ġimplementation Ġto Ġ[ Internal Repository Impl ]. Ċ Ġ* Ċ Ġ* Ġ[ Enable Jpa Audit ing ] Ġenables ĠJ PA Ġaudit ing Ġvia Ġannotations Ġ[ Created Date ], Ġ[ CreatedBy ], Ġ[ Last ModifiedDate ], Ġand Ġ[ LastModified By ]. Ċ Ġ* ĠEntities Ġmust Ġbe Ġannotated Ġwith Ġan Ġ[ Audit ing Entity Listener ] Ġto Ġbe Ġaudit ed . Ċ Ġ* Ċ Ġ* ĠImport ant Ġnotes Ġregarding ĠSpring Ġannotation - based Ġtransactions , Ġwhen Ġusing Ġthe Ġdefault Ġproxy - mode : Ċ Ġ* Ċ Ġ* Ġ Ġ- Ġ@ Transactional Ġonly Ġworks Ġon Ġpublic Ġmethods . Ċ Ġ* Ġ Ġ- ĠOnly Ġexternal Ġmethod Ġcalls Ġcoming Ġin Ġthrough Ġthe Ġproxy Ġare Ġintercept ed . Ċ Ġ* ĠĠĠ ĠSelf - invocation Ġof Ġa Ġ@ Transactional Ġmethod Ġwill Ġnot Ġstart Ġa Ġtransaction . Ċ Ġ* Ġ Ġ- ĠThe Ġproxy Ġmust Ġbe Ġfully Ġinitialized , Ġdon 't Ġrely Ġon Ġthis Ġfeature Ġin Ġyour Ġinitialization Ġcode , Ġi . e . Ġ@ Post Construct . Ċ Ġ* Ġ Ġ- ĠIt 's Ġnot Ġrecommended Ġto Ġuse Ġ@ Transactional Ġon Ġinterfaces Ġ( repositories Ġare Ġan Ġexception ). Ċ Ġ* Ċ Ġ* Ġ[ Custom ize Ġthe ĠBase ĠRepository ]( https :// docs . spring . io / spring - data / jpa / docs / current / reference / html /# repositories . customize - base - repository ), Ċ Ġ* Ġ[ Aud itor Aware ]( https :// docs . spring . io / spring - data / commons / docs / current / reference / html /# audit ing . aud itor - aware ), Ċ Ġ* Ġ[ Using Ġ@ Transactional ]( https :// docs . spring . io / spring / docs / current / spring - framework - reference / data - access . html # transaction - decl arative - annotations ), Ċ Ġ* Ġ[ Spring ĠData ĠJ PA ĠTransaction ality ]( https :// docs . spring . io / spring - data / jpa / docs / current / reference / html /# transactions ) Ċ Ġ*/ Ċ @ Configuration Ċ @ Enable Jpa Repositories ( ĊĠĠĠ Ġrepository Base Class Ġ= ĠInternal Repository Impl :: class , ĊĠĠĠ Ġbase Package Classes Ġ= Ġ[ Application :: class ] Ċ ) Ċ @ Enable Jpa Audit ing Ċ @ Enable Transaction Management ( order Ġ= ĠTRAN SACTION _ AD VICE _ ORDER ) Ċ class ĠJ pa Config ( ĊĠĠĠ Ġprivate Ġval Ġaccount Repository : ĠAccount Repository Ċ ) Ġ{ ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠProvides Ġthe Ġauthenticated Ġaccount Ġused Ġfor Ġ[ CreatedBy ] Ġand Ġ[ LastModified By ]. ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġ@ Bean ĊĠĠĠ Ġfun Ġaccount Aud itor (): ĠAud itor Aware < Account > Ġ= ĊĠĠĠĠĠĠĠ ĠAud itor Aware < Account > Ġ{ ĠOptional . of Nullable ( account Repository . find Authenticated ()) Ġ} Ċ Ċ } Ċ