Return-Path: Delivered-To: apmail-geronimo-user-archive@www.apache.org Received: (qmail 71512 invoked from network); 15 Jun 2007 19:37:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 15 Jun 2007 19:37:39 -0000 Received: (qmail 542 invoked by uid 500); 15 Jun 2007 19:37:42 -0000 Delivered-To: apmail-geronimo-user-archive@geronimo.apache.org Received: (qmail 99825 invoked by uid 500); 15 Jun 2007 19:37:40 -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 99807 invoked by uid 99); 15 Jun 2007 19:37:39 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Jun 2007 12:37:39 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [69.147.95.77] (HELO smtp114.plus.mail.sp1.yahoo.com) (69.147.95.77) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 15 Jun 2007 12:37:35 -0700 Received: (qmail 85268 invoked from network); 15 Jun 2007 19:37:14 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Received:X-YMail-OSG:Mime-Version:In-Reply-To:References:Content-Type:Message-Id:Content-Transfer-Encoding:From:Subject:Date:To:X-Mailer; b=BoiISqlHEEt2y2D7uSpsYMlkGGjWKw6otL1quSWxGNXXuEhDXMRV30MfHjqXrt3iFtwtoqNUUTGwH2RLdOGs/Vn8qASa+92xsPFvAIhuOd4R0nCI274CnL+w4Lhe4j5DyGwmoQ5gj1g+avOJYUdNyrAomhZ8v3tKdjNlLj7w+Zg= ; Received: from unknown (HELO ?10.11.55.8?) (david_jencks@63.105.20.225 with plain) by smtp114.plus.mail.sp1.yahoo.com with SMTP; 15 Jun 2007 19:37:14 -0000 X-YMail-OSG: nSxcfW8VM1mb_.8NGMagEBdXkH3HBXlSjN8Jgv6NUiLWC_MnwkjPKRhiWOH94rsgSC_L1vqUZDMGDfPw8BTiNQJ1CNcykFYmYZ9ZEHX3icJ27eGATA-- Mime-Version: 1.0 (Apple Message framework v752.3) In-Reply-To: <4672E675.9020505@joyfulnoisewebdesign.com> References: <4672CB99.4090505@pmb.mine.nu> <4672E3EF.4050501@joyfulnoisewebdesign.com> <4672E675.9020505@joyfulnoisewebdesign.com> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: David Jencks Subject: Re: Web app with jpa -- configuration help needed Date: Fri, 15 Jun 2007 12:38:03 -0700 To: user@geronimo.apache.org X-Mailer: Apple Mail (2.752.3) X-Virus-Checked: Checked by ClamAV on apache.org I'm not sure jays' info is correct. You can get an EntityManager in a servlet as long as you look it up in jndi, just don't inject it using annotations or cache it in a field in your servlet. I think the problem is that you are looking up java:comp/env/jdbc/ jBasicDB which is where the datasource is expected to be, not the EntityManager. Also in your geronimo plan you have a persistence- unit-ref specified but you want a persistence-context-ref since you are looking for an EntityManager, not an EntityManagerFactory. I would suggest that you look up java:comp/env/jBasicDB in your servlet, and include this in your web.xml and then you won't need anything in your geronimo-web plan: jBasicDB Also I strongly recommend including a non-jta-datasource in the persistence.xml, I haven't been able to get anything to work with derby without that. mysql may be more forgiving/less prone to weird deadlocks. Leave out all the connect-to-mysql parameters in persistence.xml and use the datasource. You don't need a resource-ref anywhere if you aren't using the db directly from your servlet. I assume you've found the jpa sample under testsuite/.....? It uses derby but does show a (usually) working configuration. Hope this helps david jencks On Jun 15, 2007, at 12:20 PM, Jay D. McHugh wrote: > Peter, > > I just realized - if you are doing resource_local access, you don't > actually need the database pool. > > OpenJPA will create connections as it needs them. > > I would leave the database pool there though - it doesn't hurt > anyone having it there. > > Once you manage to get your app deployed, take a look in the jmx > viewer of the admin console under J2EE Managed Objects/Persistence > Unit to make sure it got deployed correctly. Also, when you > deploy, there will be a message dumped to the log about a property > being unrecognized - you can ignore it. It is an issue with > OpenJPA that already has a JIRA filed for it. > > Make sure you have the synchronizeMappings property set in your > persistence.xml - otherwise the Geronimo default will kick in and > try to recreate your tables and destroy all of your data. > > If I have time to try fixing my app to use the jta datasource - > I'll let you know what needs to change. > > > Jay > > Jay D. McHugh wrote: >> Hi Peter, >> >> In a webapp, you are not allowed to directly get an EntityManager >> (they aren't threadsafe). Instead, you need to get an >> EntityManagerFactory. >> >> I was originally not able to get access to a jta-datasource, I had >> to go with resource-local. I never went back to try accessing a >> database pool - so I'm going to tell you how I got things working >> in my current setup (using your values). >> >> _persistence.xml >> >> _ >> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >> version="1.0" >> xsi:schemaLocation="http://java.sun.com/xml/ns/persistence >> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> >> > name="jbasicDB"> >> >> org.apache.openjpa.persistence.PersistenceProviderImpl> provider> >> nu.m4u.jbasic.control.jpa.Users >> >> >> > value="jdbc:mysql://localhost:3306/jbasic"/> >> > value="com.mysql.jdbc.Driver"/> >> > value="xxxxx"/> >> > value="xxxxx"/> >> >> >> >> >> >> >> >> >> >> > value="true" /> >> >> > value="false" /> >> >> >> >> >> _geronimo-web.xml:_ >> >> Remove all of the persistence unit info -> >> >> >> > xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1" >> xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1" >> xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1"> >> >> >> jbasic >> jbasic2 >> war >> >> >> >> console.dbpool >> jbasicDB >> 1.0 >> rar >> >> mysql >> mysql-connector-java >> 3.1.12 >> jar >> >> >> >> /jbasic2 >> >> >> _web.xml:_ >> >> Remove the peristence info. >> >> _database pool plan:_ >> >> looks fine >> >> >> Then, in order to get an EntityManagerFactory in your servlets use >> resource injection to create a class variable: >> >> @PersistenceUnit(unitName="jbasicDB") private >> EntityManagerFactory emf; >> >> And finally, wherever you need access to an EntityManager: >> >> EntityManager em = emf.createEntityManager(); >> >> em.getTransaction().begin(); >> >> // do stuff >> >> em.getTransaction().commit(); >> >> em.close(); >> >> If you are only reading from your database, you can leave off the >> 'em.getTransaction()' stuff. But if you are modifying data - you >> will need these otherwise, when you close your EntityManager >> instances all of your changes go away. >> >> Hope this helps, >> >> >> Jay >> >> Peter Petersson wrote: >>> Hi >>> >>> Need help on resolving the following configuration problem. >>> I am trying to find out how to get a geronimo database pool >>> (mysql) used in a webapp, JPA managed in G v2.0 M6 (this is just >>> a WAR not a EAR). >>> >>> I end up stuck at deployment with the following error message. >>> >>> 13:42:42,291 ERROR [Deployer] Deployment failed due to >>> org.apache.geronimo.common.DeploymentException: At least one >>> deployment problem: >>> [org.apache.geronimo.common.DeploymentException: Could not >>> resolve reference at deploy time for query ? >>> name=jbasicDB#org.apache.geronimo.persistence.PersistenceUnitGBean. >>> No GBean references found.] >>> at >>> org.apache.geronimo.persistence.builder.PersistenceUnitRefBuilder.bu >>> ildNaming(PersistenceUnitRefBuilder.java:154) >>> at >>> org.apache.geronimo.persistence.builder.PersistenceUnitRefBuilder$ >>> $FastClassByCGLIB$$9679ec9.invoke() >>> >>> I have looked around for G/JPA configuration information but the >>> ones I have found aether deals with G:s derby db (examples >>> working fine) or is a fully fledged EAR application which is a >>> bit of an overkill as this app is meant to be used as a >>> educational "stepping stone" app for some colleagues ( and me as >>> it seems ;) ). >>> >>> I'm trying to get hold of the entity manager with the following >>> JNDI context lookup name "java:comp/env/jdbc/jbasicDB" >>> >>> Here is relevant (or not so) parts of the current incarnation of >>> the configuration: >>> >>> persistency.xml (in webapp/WEB-INF) >>> ------------------------------------------------ >>> >> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >>> version="1.0" >>> xsi:schemaLocation="http://java.sun.com/xml/ns/ >>> persistence http://java.sun.com/xml/ns/persistence/ >>> persistence_1_0.xsd"> >>> >>> >>> >>> org.apache.openjpa.persistence.PersistenceProviderImpl>> provider> >>> jdbc/jbasicDB >>> nu.m4u.jbasic.control.jpa.Users >>> >>> >>> >> value="org.apache.openjpa.jdbc.sql.MySQLDictionary"/> >>> >>> >> value="com.mysql.jdbc.Driver"/> >>> >>> >>> >>> >>> >>> ------------------------------------------------ >>> >>> geronimo-web.xml >>> ------------------------------------------------ >>> >>> >> xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1" >>> xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1" >>> xmlns:sys="http://geronimo.apache.org/xml/ns/ >>> deployment-1.1"> >>> >>> >>> jbasic >>> jbasic2 >>> war >>> >>> >>> >>> console.dbpool >>> jbasicDB >>> 1.0 >>> rar >>> >>> mysql >>> mysql-connector-java >>> 3.1.12 >>> jar >>> >>> >>> /jbasic2 >>> >>> >>> jdbc/jbasicDB>> ref-name> >>> jbasicDB >>> >>> >>> ------------------------------------------------ >>> >>> web.xml >>> ------------------------------------------------ >>> >>> >> xmlns="http://java.sun.com/xml/ns/j2ee" >>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >>> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http:// >>> java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> >>> >>> ------------------------------------------------ >>> >>> database pool plan >>> ------------------------------------------------ >>> >>> >>> >>> >>> console.dbpool >>> jbasicDB >>> 1.0 >>> rar >>> >>> >>> >>> mysql >>> mysql-connector-java >>> 3.1.12 >>> jar >>> >>> >>> >>> >>> >>> >>> javax.sql.DataSource>> connectionfactory-interface> >>> >>> jbasicDB >>> xxxx>> config-property-setting> >>> >> name="Driver">com.mysql.jdbc.Driver >>> xxxx>> config-property-setting> >>> >> name="ConnectionURL">jdbc:mysql://localhost:3306/jbasic>> property-setting> >>> >>> >>> >>> 10 >>> 0 >>> >>> >>> >>> >>> >>> >>> >>> >>> ------------------------------------------------ >>> >>> Anny help is appreciated ! >>> /Peter Petersson >>> >>> >>> >> >> >>