Return-Path: Delivered-To: apmail-geronimo-user-archive@www.apache.org Received: (qmail 13816 invoked from network); 15 Sep 2009 18:46:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 15 Sep 2009 18:46:45 -0000 Received: (qmail 59202 invoked by uid 500); 15 Sep 2009 18:46:44 -0000 Delivered-To: apmail-geronimo-user-archive@geronimo.apache.org Received: (qmail 59147 invoked by uid 500); 15 Sep 2009 18:46:44 -0000 Mailing-List: contact user-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: user@geronimo.apache.org List-Id: Delivered-To: mailing list user@geronimo.apache.org Received: (qmail 59139 invoked by uid 99); 15 Sep 2009 18:46:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Sep 2009 18:46:44 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of jaydmchugh@gmail.com designates 209.85.221.201 as permitted sender) Received: from [209.85.221.201] (HELO mail-qy0-f201.google.com) (209.85.221.201) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Sep 2009 18:46:33 +0000 Received: by qyk39 with SMTP id 39so3498888qyk.31 for ; Tue, 15 Sep 2009 11:45:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :x-enigmail-version:content-type:content-transfer-encoding; bh=9WiKbdfy9nWeZKP9bkSjf5FxTibcKcMeImTe8w6pomk=; b=MADjSwqLk3CsnMP6XfU5iN6/OoWga6hFf60SH7iHM5ZRY2+/HTatEwB8Oxh+LOnjfy n7eQnXoJvXaJJgGe219G4rH5tnJPn7mMd/JUavvWvc272SBDeNFf5i9SC5peLtL9YZzv JPbEb4qsMxhhMiBofr8Nde2QMqFUlcJtDiFkQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; b=pIoLMbpKEaQRNFDMvRMDHBuhMIIHMl8rRA5atoAGV6PY158loexWatebJCjbDqd+vq e3yKa17IuGYDZ4ZELicN7MmnBwoiUWG0vY0aLnZep/Jf/GxyMUUhYcn3p3OzsJlKEH93 yEQSFfRtcimC/F/RRlvyd/8TMZ7ZE8NGRltyE= Received: by 10.224.72.12 with SMTP id k12mr6640079qaj.62.1253040308339; Tue, 15 Sep 2009 11:45:08 -0700 (PDT) Received: from ?172.16.3.3? (198.pubint.com [66.84.139.198]) by mx.google.com with ESMTPS id 4sm144700qwe.55.2009.09.15.11.45.06 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 15 Sep 2009 11:45:07 -0700 (PDT) Message-ID: <4AAFE0AF.601@gmail.com> Date: Tue, 15 Sep 2009 13:45:03 -0500 From: "Jay D. McHugh" User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: user@geronimo.apache.org Subject: Re: EntityManager & Servlets References: <25221488.post@talk.nabble.com> <25226546.post@talk.nabble.com> In-Reply-To: <25226546.post@talk.nabble.com> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Sorry for the late reply to this. Geronimo should not allow you to add container managed entity managers to servlets. They would not be thread safe. I haven't looked at the example in a while - but I believe it is using a stateless session bean to access the entity manager. That is perfectly acceptable (and correct)... I just took a look at the example and it does in fact use a stateless bean (AccountBean). So, that is why it is able to use container managed persistence. I don't think that it would actually make projects simpler to move the data access logic into each of the servlets that need it. For me at least, centralizing the logic into session beans means that I am forced to consider exactly what I will be doing with the data and only write the code once to do it. Hope that helps, Jay tornike wrote: > Yes, but if it's in their example maybe it's OK for Geronimo to use container > managed EntityManager with the servlet and there won't be any threading > issues. If it's true then we wouldn't need any EJB's in the project and > simply communicate to JPA entities even when using container managed > EntityManager. As far as I know this method is discouraged but if it's ok to > do in Geronimo it would greatly simplify many projects. > > > > Fredrik Jonson-3 wrote: >> In <25221488.post@talk.nabble.com> tornike wrote: >> >>> EntityManager is not thread safe and it should not be injected into the >>> servlet. (container managed one) However in the example of ejb-JPA >>> >>> http://cwiki.apache.org/GMOxDOC21/container-managed-persistence-with-jpa.html >>> >>> I have tested the example works without problems so are there conditions >>> when it can be done or am I understanding it the wrong way? >> I'd say the example is wrong or at least careless. So I'm also interested >> if someone thinks otherwise. >> >> If I would have done it I'd inject a EntityManagerFactory in the servlet >> and >> acquired a new EntityManager from the pool for each request to doGet >> method: >> >> public class Example extends HttpServlet { >> @PersistenceUnit >> private EntityManagerFactory emf; >> >> @Override >> protected void doGet(HttpServletRequest request, HttpServletResponse >> response) >> throws ServletException, IOException { >> EntityManager em = emf.createEntityManager(); >> // do stuff >> >> -- >> Fredrik Jonson >> >> >> >