Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id BED37200B30 for ; Mon, 4 Jul 2016 10:19:41 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id BD735160A65; Mon, 4 Jul 2016 08:19:41 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 106FE160A55 for ; Mon, 4 Jul 2016 10:19:40 +0200 (CEST) Received: (qmail 87451 invoked by uid 500); 4 Jul 2016 08:19:39 -0000 Mailing-List: contact users-help@deltaspike.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@deltaspike.apache.org Delivered-To: mailing list users@deltaspike.apache.org Received: (qmail 87440 invoked by uid 99); 4 Jul 2016 08:19:39 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Jul 2016 08:19:39 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id D84D5186CEF for ; Mon, 4 Jul 2016 08:19:38 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -2.128 X-Spam-Level: X-Spam-Status: No, score=-2.128 tagged_above=-999 required=6.31 tests=[RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, RP_MATCHES_RCVD=-1.426, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id fOoMKdlxUTcX for ; Mon, 4 Jul 2016 08:19:37 +0000 (UTC) Received: from DUB004-OMC2S20.hotmail.com (dub004-omc2s20.hotmail.com [157.55.1.159]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 42A875FB06 for ; Mon, 4 Jul 2016 08:19:37 +0000 (UTC) Received: from DUB126-W73 ([157.55.1.137]) by DUB004-OMC2S20.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Mon, 4 Jul 2016 01:19:31 -0700 X-TMN: [EtpNNkdbs5kCDKzSlSUpDHcsH3K99l50] X-Originating-Email: [kalgon@hotmail.com] Message-ID: From: Xavier Dury To: "users@deltaspike.apache.org" Subject: Some thoughts about EntityManagerResolver and EXTENDED PersistenceContext Date: Mon, 4 Jul 2016 10:19:31 +0200 Importance: Normal Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 04 Jul 2016 08:19:31.0348 (UTC) FILETIME=[CA3CC540:01D1D5CC] archived-at: Mon, 04 Jul 2016 08:19:41 -0000 Hi=2C=0A= =0A= I know that the EXTENDED PersistenceContext usage is not recommended by the= DeltaSpike team but I would like to have a discussion about it.=0A= =0A= I am currently developing a small-scale intranet application where our core= -business entity model has a lot of levels which can be lazily expanded/col= lapsed in the UI (written in JSF). In this case=2C I really like to be able= to use an EXTENDED PersistenceContext and not really care about eagerly lo= ading all associations as=2C most of the time=2C deep levels won't even be = expanded (the decision is left to the user to expand what is needed). And t= his is the concept that made me like Seam when it was first released.=0A= =0A= Now=2C I have some concerns about the EntityManagerResolver:=0A= =0A= - As an EntityManagerResolver kinda "extracts" the EM from its owning @Stat= eful bean=2C what guarantees do I have that this EM won't be used in concur= rent (AJAX) requests? If I am not mistaken=2C all method calls on a @Statef= ul bean must be synchronized/locked but as the EM is not thread-safe and wo= n't be called in the context of a call on its owning SFSB=2C this could be = problematic. (Since JPA 2.1=2C I've seen a synchronization attribute on @Pe= rsistenceContext but it has nothing to do with concurrent synchronization.)= =0A= =0A= - Correct me if I am wrong but the JEE spec does not (yet) define how an EM= that was "extracted" from its owning bean should behave.=0A= =0A= Therefore=2C wouldn't it be better to replace the EntityManagerResolver by = some sort of EntityManagerHolder like this one:=0A= =0A= public interface EntityManagerHolder {=0A= =A0=A0 =A0=0A= =A0=A0=A0 T executeCallback(EntityManagerCallback callback)=3B=0A= }=0A= =0A= public interface EntityManagerCallback {=0A= =0A= =A0=A0=A0 T execute(EntityManager entityManager)=3B=0A= }=0A= =0A= and have it implemented like this:=0A= =0A= @Stateful=0A= @TransactionManagement(BEAN) // TXs should not be handled here=0A= @ViewScoped // for example=0A= public class MyEntityManagerHolder implements EntityManagerHolder {=0A= =0A= =A0=A0=A0 @PersistenceContext(type =3D EXTENDED)=0A= =A0=A0 =A0private EntityManager entityManager=3B=0A= =0A= =A0=A0 =A0public T executeCallback(EntityManagerCallback callback) {= =0A= =A0=A0 =A0=A0=A0 =A0return callback.execute(this.entityManager)=3B=0A= =A0=A0 =A0} =0A= }=0A= =0A= Here=2C all calls on the EntityManager will happen inside a call on the SFS= B which should guarantee that only one thread at a time may use the EM and = it also circumvents the gap in the specification.=0A= =0A= What do you think? Is there something I forgot to take into account?=0A= =0A= Thanks=2C=0A= =0A= Regards=2C=0A= =0A= Xavier =