Return-Path: X-Original-To: apmail-deltaspike-users-archive@www.apache.org Delivered-To: apmail-deltaspike-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 90491109F7 for ; Fri, 2 Jan 2015 18:40:55 +0000 (UTC) Received: (qmail 51280 invoked by uid 500); 2 Jan 2015 18:40:56 -0000 Delivered-To: apmail-deltaspike-users-archive@deltaspike.apache.org Received: (qmail 51245 invoked by uid 500); 2 Jan 2015 18:40:56 -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 51214 invoked by uid 99); 2 Jan 2015 18:40:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Jan 2015 18:40:54 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of danielsoro@gmail.com designates 209.85.216.52 as permitted sender) Received: from [209.85.216.52] (HELO mail-qa0-f52.google.com) (209.85.216.52) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Jan 2015 18:40:28 +0000 Received: by mail-qa0-f52.google.com with SMTP id v10so9848259qac.11 for ; Fri, 02 Jan 2015 10:40:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=tp4sr3qtimDSvt0QkrqwURohccAdReCFdvj/PgZ1jLo=; b=KIFYcv1lzoX8dTpwo6XFTxgXBLBwKG9Exuk1B9frHEenda0Zhn8gLxX/YLNh1NB9BR x5Rn08Ebu/Ev/GOgcUEtpvqqWWWccIrXWFCBQo5rha0xLTk90EZmNTDJKC4xUH3F8KJf OfS1BKajCcHbM/byfA0saAhWDo+0IPJgCjNG/MRzKgk4GXVPCkRfoPlnjQJpVevMZ6AY sXBxG0xFbq9yK13pWDIyg5LIaKnHNSEUBrDUfnus4JdAb/6fO0iSq1APyZVoy8KDcSLB xEp+iGVfPaEVXaXDbZpPTL764pkZD+8AQXSmdw9HuejDE5DS5RUMVHQpYNj5BOqi6Brb QTFA== MIME-Version: 1.0 X-Received: by 10.224.21.133 with SMTP id j5mr127850767qab.83.1420224027345; Fri, 02 Jan 2015 10:40:27 -0800 (PST) Received: by 10.229.112.135 with HTTP; Fri, 2 Jan 2015 10:40:27 -0800 (PST) In-Reply-To: References: Date: Fri, 2 Jan 2015 18:40:27 +0000 Message-ID: Subject: Re: Setting the persistence-unit name declaratively with @PersistenceContext annotation From: Daniel Cunha To: users@deltaspike.apache.org Content-Type: multipart/alternative; boundary=001a11c29e42a6c845050bafacf1 X-Virus-Checked: Checked by ClamAV on apache.org --001a11c29e42a6c845050bafacf1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Can fix it with JNDI lookup? On Fri, Jan 2, 2015 at 6:10 PM, Rodrigo Uch=C3=B4a wrote: > Daniel, > > That would create an *application managed* EntityManager, wouldn't it? It > seems like an alternative, but I hope there's a more elegant approach tha= t > would not prevent me from using a *container managed* EntityManager. > > On Fri, Jan 2, 2015 at 3:29 PM, Daniel Cunha wrote= : > > > Can injectionPoint fix it? > > > > You can create your annotation where you set the unitName. > > So, you set the unitName. > > In your produce, get the InjectionPoint, read the annotation and set > > unitName in Persistence.createEntityManagerFactory(...); > > So, you can create the entityManger with this EntityManagerFactory and > > specific unitname. > > > > I think that can be a way. > > > > > > > http://docs.oracle.com/javaee/7/api/javax/persistence/Persistence.html#cr= eateEntityManagerFactory(java.lang.String) > > > > > http://docs.oracle.com/javaee/7/api/javax/persistence/EntityManagerFactor= y.html#createEntityManager() > > > > > http://docs.oracle.com/javaee/7/api/javax/enterprise/inject/spi/Injection= Point.html#getAnnotated() > > > > > http://docs.oracle.com/javaee/7/api/javax/enterprise/inject/spi/Annotated= .html#getAnnotation(java.lang.Class) > > > > On Fri, Jan 2, 2015 at 5:02 PM, Rodrigo Uch=C3=B4a > > wrote: > > > > > Hi everyone! > > > > > > I'm developing an API, a simple utility jar, for persistence (generic= ) > > > operations. The lib itself does not provide any persistence.xml file, > it > > > takes into account that all its clients will have one to configure > their > > > own persistence unit. > > > > > > Inside my API I can't make assumptions about the persistence unit nam= e > > for > > > the clients, so I'm simply doing something like this: > > > > > > *public class MyGenericDAO {* > > > * @Inject* > > > * EntityManager em;* > > > *}* > > > > > > > > > ... And every client who depends on the API will have a "Resource > > > Producer": > > > > > > *public class ResourcesProducer {* > > > * @Produces* > > > * @PersistenceContext( unitName =3D "some-pu")* > > > * private EntityManager entityManager;* > > > *}* > > > > > > > > > This works as expected as long as each client have a single persisten= ce > > > unit configured. The injection point in MyGenericDAO will resolve to > > > "some-pu" because there's only one. But if there are multiple > persistence > > > units it won't work. > > > > > > This was easy to solve with Seam (and also Spring) as we could > > > declaratively initialize any bean (component) property. As far as my > > > knowledge on CDI goes, this can't be done with CDI/JavaEE alone. So I > was > > > wondering with Deltaspike has any feature to help with this issue. > > > > > > Regards, > > > > > > > > > > > -- > > Daniel Cunha (soro) > > > --=20 Daniel Cunha (soro) --001a11c29e42a6c845050bafacf1--