Return-Path: Delivered-To: apmail-geronimo-user-archive@www.apache.org Received: (qmail 27565 invoked from network); 17 Jul 2010 17:35:37 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 17 Jul 2010 17:35:37 -0000 Received: (qmail 33910 invoked by uid 500); 17 Jul 2010 17:35:36 -0000 Delivered-To: apmail-geronimo-user-archive@geronimo.apache.org Received: (qmail 33778 invoked by uid 500); 17 Jul 2010 17:35:35 -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 33771 invoked by uid 99); 17 Jul 2010 17:35:35 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 17 Jul 2010 17:35:35 +0000 X-ASF-Spam-Status: No, hits=1.3 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [98.136.44.62] (HELO smtp107.prem.mail.sp1.yahoo.com) (98.136.44.62) by apache.org (qpsmtpd/0.29) with SMTP; Sat, 17 Jul 2010 17:35:28 +0000 Received: (qmail 98449 invoked from network); 17 Jul 2010 17:35:07 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Content-Transfer-Encoding:Message-Id:References:To:X-Mailer; b=IiLoAD9IPE7ZD3dAl2PKMM7Pbm6EpyJz/Jno5LpzzL4nufbFtadDVAJh9IwIJyfdefU+A/dyp1qgvWDMPO5JlV68lDx55taVNuMhGzVIHNpdQrNnObBYK9wstJOjtHBsp2tULcCMW3aNFotF9p8zwvbRb/V49W3R+/YKVfZMYJg= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1279388107; bh=cBxcYGsTgYv+3o6krZ25pvbeuDOMhRZWl8yZnSSm4pY=; h=Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Content-Transfer-Encoding:Message-Id:References:To:X-Mailer; b=3+dk3Y5++hnOKeWpl0+37hCyEup5mVeTrmTUntpCXOkopHxarJbTqCYnR2Jp1FELpbin++5FrNxxRDkj1w0myTS/AY64ukKeukKcv8YowzXQgHv8HxT8YwYamvV3DSiOpE+0Ajpm6PdUcnrQi+GLbbgkcFASo9njd3sMM9GMVRY= Received: from [10.0.1.3] (david_jencks@76.76.148.215 with plain) by smtp107.prem.mail.sp1.yahoo.com with SMTP; 17 Jul 2010 10:35:06 -0700 PDT X-Yahoo-SMTP: .9oIUzyswBANsYgUm_5uPui0skTnzGJXJQ-- X-YMail-OSG: xywjP78VM1klu4083Xny9YmxQoNWGGK4IO7SZCdwz.A.qSA sh3E9tBvTLZFeOl1NCYKm48qyS5B25nMc9YzBv2m6gYooC.4fBC26xjZn4f7 n9ugGG.ndTGOtqroDuVdZEWsBoFgnRGdENHJfJlZ8VG9SSk8lPfVwTR3bNbD zO182IEbTONNiq7ExXZiUSBnhAaidbef2lLSqNAp6tqGJx7tBc9dXTUDgQO4 Ao4A6tVjF._AbMJbiP8mIcEoMxR_AH2A9MPlpTWSsYj5M8b7tGLBh.M6Gp7B 1JcGDUnlqp0jsCxc_X7YNVHZcQ5nuIsRfntd6JgIkHT0uYsT0Zlx3K0OIhTv ZfF5M8UHxrHj_VzWx X-Yahoo-Newman-Property: ymail-3 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1081) Subject: Re: Geronimo 2.2 + Spring + Hibernate and a Geronimo managed DB Pool with XA driver From: David Jencks In-Reply-To: <1279371451900-974846.post@n3.nabble.com> Date: Sat, 17 Jul 2010 10:35:05 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: References: <1275860383509-874759.post@n3.nabble.com> <53B4A591-E7E8-4D2B-B1FB-C17524FD7E0C@gmail.com> <1279244632622-971182.post@n3.nabble.com> <1279339876370-974144.post@n3.nabble.com> <1279371451900-974846.post@n3.nabble.com> To: user@geronimo.apache.org X-Mailer: Apple Mail (2.1081) X-Virus-Checked: Checked by ClamAV on apache.org On Jul 17, 2010, at 5:57 AM, Billy Vandory wrote: >=20 > Hi David, thanks again for your reply. Reading over my emails I can = see how > it could be cryptic, as I assume everyone knows everything about what = I am > doing :)=20 >=20 > We are using JPA with hibernate as the provider on geronimo. We want = the > EntityManager injected directly in the DAO via spring, but it seems = the > container will not do that, it will only inject inside an EE = component, so > we want Spring to handle the injection. This is something that spring > offers, the ability to use the @PersistenceContext in any object > (apparently). However using the @PersistenceContext annotation in the = DAO > results in: >=20 > Caused by: javax.naming.NotContextException: jdbc/walmart0192 >=20 > So then I decided to see if we could inject the entity manager into = our EJB > using @PersistenceContext without spring as a test, and that worked = fine.=20 > The next test was to see if we could use a JNDI lookup on the dbpool, = in the > EJB directly, and that failed, and then we tried using @Resource in = the EJB > and that failed as well. This was the motivation for doing a lookup = inside > the EJB using JNDI - just a test. >=20 > This takes me right up to my last msg. >=20 > On your advise I added the dependency to my dbpool in my geronimo dd, = and > added the following to ejb-jar.xml >=20 > CategoryEJB >=20 > = com.wakapeek.common.bean.RemoteCategory= > com.wakapeek.ejb.CategoryEJB=20 > Stateless=20 > Container=20 >=20 > > jdbc/testmydb > javax.sql.DataSource > Container > Shareable > >=20 >=20 > Well that worked! The @Resource injection and JNDI lookup in the EJB = now > locate the datasource just great! >=20 > I then took all that lookup / resource stuff out of the EJB and = reverted to > our earlier config, where the Entity Manager is to be injected into = the DAO > via the @PersistenceContext annotation and it fails with the Caused = by: > javax.naming.NotContextException: jdbc/walmart0192 >=20 > (I'm using different db's. Sometimes it's testmydb, the other ones are = dev > db's.) >=20 > As to the flow of this thing, it's as follows: >=20 > This is just a backend EJB layer. No web server, no servlets, no = web.xml, > etc. Just EJB and JPA on geronimo bundled and deployed as an ear file >=20 > So now what is happening is, in a standalone test we lookup a = stateless EJB > and invoke a method - A service object is injected into the EJB via = spring, > then the DAO is injected into the service object and the entity = manager is > (supposed to be) injected into the DAO via the @PersistenceContext > annotation. This is where it generates the stack trace throwing a > NotContextException. =20 >=20 > In the EJB, this is the method we invoke: >=20 > @Override > public CategoryDTO getCategoriesTree() { > // test jndi lookup from this ejb (THIS NOW WORKS = !!) =09 > try { > InitialContext ctx =3D new InitialContext(); > DataSource ds =3D (DataSource) = ctx.lookup("java:jdbc/testmydb"); Really? it shouldn't: this should work: DataSource ds =3D (DataSource) = ctx.lookup("java:comp/env/jdbc/testmydb"); > Connection con =3D ds.getConnection();=20 > } > catch (Exception e) { =09 > logger.error(e); > } > =09 > // call the service layer > return categoryService.getCategoriesTree(); > }=09 >=20 >=20 > The CategoryService object has the DAO injected via spring. This = service > object is marked as a spring @Service >=20 > public void setCategoryDao(CategoryDao dao) { =09 > this.categoryDao =3D dao; > } >=20 > And the DAO has the EntityManager injected via spring. The DAO is = marked as > @Transactional >=20 > @Required > @PersistenceContext(name =3D "wakapeek-jpa")=09 > public void setEntityManager(EntityManager entityManager) { =09 > this.em =3D entityManager; =20 > } >=20 > and again, the same problem: Caused by: = javax.naming.NotContextException: > jdbc/walmart0192 >=20 > So Im not sure why this all works but Spring can't handle it. Can you show the spring configuration for the PU? Does it reuse the = same persistence.xml as geronimo finds? I think that for spring you = need to specify jndi names for the jta-datasource and non-jta-datasource = and for geronimo you definitely can't. So you may need to turn off the = jpa deployer in geronimo before deploying your ear to avoid conflicts. = I also don't know what triggers spring to actually try to get the = datasource from jndi. If it's done in a thread called from your ejb, = then, if you keep the stuff so the jndi lookup works in the ejb, you can = use the same jndi name in the configuration for spring, (the name I = think should be "java:comp/env/jdbc/testmydb") If it's called in some = other thread you'll have to use the jca: name that doesn't seem to work = yet. The jca name should be printed out in the log... so please check that = you are using the one that is printed, maybe some configuration changed = and so did the name. thanks david jencks >=20 > I'm going to cross post this into the Spring forum now, as it's = behaving > correctly in the EJB. Thanks very much for all your help and having = the > patience to sift through my messages. If I ever find the solution, I = will > definately put up a faq somewhere on dbpool + spring + geronimo + jpa. = It's > been interesting configuring geronimo with hibernate. If you have any > thoughts, I'd love to hear them! :) >=20 > - billworth vandory > --=20 > View this message in context: = http://apache-geronimo.328035.n3.nabble.com/Geronimo-2-2-Spring-Hibernate-= and-a-Geronimo-managed-DB-Pool-with-XA-driver-tp874759p974846.html > Sent from the Users mailing list archive at Nabble.com.