Or even leverage the EntityManagerAware interface. On Thu, Nov 26, 2015 at 9:50 AM Thomas Hug <[email protected]> wrote:
> Hi Robin > > Did you already look at the Query Delegates? > http://deltaspike.apache.org/documentation/data.html#Extensions > > To summarize it for your context: > - You can define a new interface with the add method > - Provide an implementation of it which implements the new interface as > well as DelegateQueryHandler. You can access the entityManager over an > injected QueryInvocationContext (as in the docs). > - Have your repositories implement / extend the new interface > - Then ... No that's actually all, use the new add method :) > > Hope this helps. > > Cheers, > Thomas > > > On Thu, Nov 26, 2015 at 1:27 PM, Roos, Robin <[email protected]> > wrote: > > > Of course, the method would be called add() and would return void....this > > is consistent with the notion that Repositories model a persistent > > Collection. > > > > @RequiresTransaction > > public void add(E entity) { > > this.entityManager().persist(entity); > > } > > > > -----Original Message----- > > From: Roos, Robin [mailto:[email protected]] > > Sent: 26 November 2015 12:21 > > To: [email protected] > > Subject: Extending EntityRepository interface and EntityRepositoryHandler > > class > > > > Hi Folks > > > > My developers are building a JPA application in which Domain objects > > remain entirely within the transactional context. This means we never do > > detach/merge, whether implicitly or explicitly. > > > > I am concerned that the default Save() implementation in > > EntityRepositoryHandler would incur a merge() if an already-persistent > > instance was passed to save(). > > > > > > @RequiresTransaction > > public E save(E entity) { > > if(this.context.isNew(entity)) { > > this.entityManager().persist(entity); > > return entity; > > } else { > > return this.entityManager().merge(entity); > > } > > } > > > > To preclude this I would like to extend EntityRepositoryHandler to > provide > > an implementation of a new method add(), as follows: > > > > @RequiresTransaction > > public E save(E entity) { > > this.entityManager().persist(entity); > > return entity; > > } > > > > Presumably I would put this method signature into interface > > MyEntityRepository extends EntityRepository, and the implementation into > > class MyEntityRepositoryHandler extends EntityRepositoryHandler. > > Repository interfaces would then implement MyEntityRepository. (We do > not > > have any Repository "implementations" since DeltaSpike takes care of that > > for us.) > > > > But how do I get it all joined up, i.e. how to I nominate my new Handler > > to be used when CDI is working its magic on the Repository interfaces? > > > > Thanks, Robin. > > > > > > > *********************************************************************************************************** > > Nissan Motor Manufacturing (UK) Limited is a limited liability company > > registered in England and Wales under number 01806912 with its registered > > office at Washington Road, Sunderland, Tyne and Wear SR5 3NS. > > > > CONFIDENTIALITY NOTICE AND DISCLAIMER > > > > This message including any attachments to it (Message) is private and > > confidential and may contain proprietary or legally privileged > > information. If you have received this Message in error, please send an > > email to [email protected] with a copy of this Message > and > > remove it from your system. You must not, directly or indirectly, use, > > disclose, distribute, print or copy any part of this Message if you are > not > > the intended recipient. The NISSAN EUROPE S.A.S group of companies > (NISSAN) > > reserve the right to monitor all e-mail communications through its > networks. > > > > NISSAN is not liable for the proper/complete transmission or any delay in > > the receipt of this Message . Whilst NISSAN takes care to protect its > > systems from electronic virus attack or other harmful event, NISSAN gives > > no warranty that this Message is free of any virus or other harmful > matter > > and accepts no liability for any loss or damage resulting from the > > recipient receiving, opening or using it. > > > > Any views or opinions expressed in this Message are those of the author > > and do not necessarily represent those of NISSAN. > > > > > *********************************************************************************************************** > > > > > > > *********************************************************************************************************** > > Nissan Motor Manufacturing (UK) Limited is a limited liability company > > registered in England and Wales under number 01806912 with its registered > > office at Washington Road, Sunderland, Tyne and Wear SR5 3NS. > > > > CONFIDENTIALITY NOTICE AND DISCLAIMER > > > > This message including any attachments to it (Message) is private and > > confidential and may contain proprietary or legally privileged > > information. If you have received this Message in error, please send an > > email to [email protected] with a copy of this Message > and > > remove it from your system. You must not, directly or indirectly, use, > > disclose, distribute, print or copy any part of this Message if you are > not > > the intended recipient. The NISSAN EUROPE S.A.S group of companies > (NISSAN) > > reserve the right to monitor all e-mail communications through its > networks. > > > > NISSAN is not liable for the proper/complete transmission or any delay in > > the receipt of this Message . Whilst NISSAN takes care to protect its > > systems from electronic virus attack or other harmful event, NISSAN gives > > no warranty that this Message is free of any virus or other harmful > matter > > and accepts no liability for any loss or damage resulting from the > > recipient receiving, opening or using it. > > > > Any views or opinions expressed in this Message are those of the author > > and do not necessarily represent those of NISSAN. > > > > > *********************************************************************************************************** > > > > >
