Return-Path: Delivered-To: apmail-openjpa-users-archive@locus.apache.org Received: (qmail 9809 invoked from network); 24 Aug 2007 01:09:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 24 Aug 2007 01:09:04 -0000 Received: (qmail 6891 invoked by uid 500); 24 Aug 2007 01:09:01 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 6866 invoked by uid 500); 24 Aug 2007 01:09:00 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 6857 invoked by uid 99); 24 Aug 2007 01:09:00 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Aug 2007 18:09:00 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of plinskey@gmail.com designates 64.233.166.178 as permitted sender) Received: from [64.233.166.178] (HELO py-out-1112.google.com) (64.233.166.178) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Aug 2007 01:08:56 +0000 Received: by py-out-1112.google.com with SMTP id f31so1398686pyh for ; Thu, 23 Aug 2007 18:08:35 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=gUxiWtofQlndKBJjj2cqdQI6jTY8gSTsPXUnfNQJoJadr2VYaZlJkOYfkqy4Xb4iycaxZts2fgO8tC2Av4FdAE80R1xQxtfN5ltq2vmlrD7h80GKUQkHN8AYsj4DanMrQ+FigZ4vIHkV7CBDjBf54c0V1yitHqyb3RLVbPGk9LA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Ttwv8b9sNgN5dspYuVzofS+fRHGeOJs5rSsOg8qtocopDMSBNBdvKtVh4RjVBbuVP3alL+1tBKwEUBDuV4q6T3Ul07/NaA6LfDK8G/n9f/9/PZqNByEsniU+eeAcwMo01/NAqkllSlv+crDeBtrwULyRi/nVt4TYKTkmNqe+OWA= Received: by 10.35.27.1 with SMTP id e1mr2818499pyj.1187917714650; Thu, 23 Aug 2007 18:08:34 -0700 (PDT) Received: by 10.35.100.9 with HTTP; Thu, 23 Aug 2007 18:08:34 -0700 (PDT) Message-ID: <7262f25e0708231808r3f34911bpe172f600f35ddd5c@mail.gmail.com> Date: Thu, 23 Aug 2007 18:08:34 -0700 From: "Patrick Linskey" To: users@openjpa.apache.org Subject: Re: Connection usage In-Reply-To: <967946b0708231736x3dbd03e2j7a7fb862f3a3caa5@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <967946b0708230621k3ab9248blcffae224778071b@mail.gmail.com> <7262f25e0708230917s5af1487byc5982e1d0e250d8c@mail.gmail.com> <967946b0708230938u52ec7f40m766b816d6aecf204@mail.gmail.com> <7262f25e0708230956h6008ed0h9f3dcd5302bff868@mail.gmail.com> <967946b0708231736x3dbd03e2j7a7fb862f3a3caa5@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org Hi, You can definitely specify just the foreign keys that you care about in your annotations / XML. In that case, OpenJPA will only consider those FKs when doing dependency analysis. Currently, in my opinion, OpenJPA does not do enough eager loading of metadata during deployment. This dates back to OpenJPA's heritage of supporting dynamic discovery of classes, but when you have to list the classes anyways, it should be able to do more-eager loading. It would be interesting to know if things get resolved by putting an emf.createEntityManager().close() call somewhere before you do any real work in the application. -Patrick On 8/23/07, Christian Defoy wrote: > I found the problem... > > > > I guess that property forces OpenJPA to load up definitions for all > foreign keys. I added the following property defined in my > persistence.xml file. It comes from a previous post I mentioned that > entities were deleted prior to their embedded objects and that was > violating foreign keys. > > The objects I am currently creating contain only partial information > from the database and they have many foreign keys that I don't care > about. These extra foreign keys could be ignored. Is there a way to > tell OpenJPA to only load certain foreign keys? Or is there a way to > tell OpenJPA to do that up front so that the normal processing only > takes one connection? > > My persistence.xml contains the three class names Command, > ShapeCommand and AddShapeCommand. The attibutes of these objects are > all basic types (namely int, Integer, Date and String). > > ex5.Command > ex5.ShapeCommand > ex5.AddShapeCommand > > A total of eight additional foreign keys are set on the Command table > for the various enum values and the like. When I step through the > code I see the foreign keys and their tables get loaded. > > Christian > > > On 8/23/07, Patrick Linskey wrote: > > Hi, > > > > Are you listing your persistent types in your persistence.xml file? > > > > The connection is being obtained while building up the mapping > > information for the class, which indicates that the class meta data > > was not fully populated by the time that the code started executing. > > > > -Patrick > > > > On 8/23/07, Christian Defoy wrote: > > > Hi Patrick, > > > > > > Here is the stack trace of the second call to getConnection(): > > > > > > java.lang.Exception: Stack trace > > > at java.lang.Thread.dumpStack(Thread.java:1158) > > > at ex5.ConnectionPool.getConnection(ConnectionPool.java:325) > > > at org.apache.openjpa.lib.jdbc.DelegatingDataSource.getConnection(DelegatingDataSource.java:106) > > > at org.apache.openjpa.lib.jdbc.DecoratingDataSource.getConnection(DecoratingDataSource.java:87) > > > at org.apache.openjpa.jdbc.schema.LazySchemaFactory.generateSchemaObject(LazySchemaFactory.java:140) > > > at org.apache.openjpa.jdbc.schema.LazySchemaFactory.findTable(LazySchemaFactory.java:91) > > > at org.apache.openjpa.jdbc.meta.MappingInfo.createTable(MappingInfo.java:466) > > > at org.apache.openjpa.jdbc.meta.ClassMappingInfo.getTable(ClassMappingInfo.java:229) > > > at org.apache.openjpa.jdbc.meta.strats.FullClassStrategy.map(FullClassStrategy.java:71) > > > at org.apache.openjpa.jdbc.meta.ClassMapping.setStrategy(ClassMapping.java:345) > > > at org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(RuntimeStrategyInstaller.java:55) > > > at org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRepository.java:313) > > > at org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository.java:605) > > > at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:492) > > > at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:288) > > > at org.apache.openjpa.meta.MetaDataRepository.resolveMeta(MetaDataRepository.java:524) > > > at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:484) > > > at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:288) > > > at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:343) > > > at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getClassMetaData(JPQLExpressionBuilder.java:154) > > > at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.resolveClassMetaData(JPQLExpressionBuilder.java:134) > > > at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateMetaData(JPQLExpressionBuilder.java:214) > > > at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateMetaData(JPQLExpressionBuilder.java:184) > > > at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateType(JPQLExpressionBuilder.java:177) > > > at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.access$500(JPQLExpressionBuilder.java:64) > > > at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder$ParsedJPQL.populate(JPQLExpressionBuilder.java:1671) > > > at org.apache.openjpa.kernel.jpql.JPQLParser.populate(JPQLParser.java:55) > > > at org.apache.openjpa.kernel.ExpressionStoreQuery.populateFromCompilation(ExpressionStoreQuery.java:148) > > > at org.apache.openjpa.kernel.QueryImpl.newCompilation(QueryImpl.java:649) > > > at org.apache.openjpa.kernel.QueryImpl.compilationFromCache(QueryImpl.java:630) > > > at org.apache.openjpa.kernel.QueryImpl.compileForCompilation(QueryImpl.java:596) > > > at org.apache.openjpa.kernel.QueryImpl.compileForExecutor(QueryImpl.java:658) > > > at org.apache.openjpa.kernel.QueryImpl.getOperation(QueryImpl.java:1483) > > > at org.apache.openjpa.kernel.DelegatingQuery.getOperation(DelegatingQuery.java:123) > > > at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:219) > > > at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:269) > > > at ex5.DatabaseCommandProcessor.processPendingCommands(DatabaseCommandProcessor.java:342) > > > at ex5.DatabaseCommandProcessor.access$1(DatabaseCommandProcessor.java:326) > > > at ex5.CommandScanner.run(DatabaseCommandProcessor.java:460) > > > at java.util.TimerThread.mainLoop(Timer.java:512) > > > at java.util.TimerThread.run(Timer.java:462) > > > > > > The code looks like this: > > > > > > EntityManager manager = factory.createEntityManager(); > > > Query query = manager.createQuery( "some query on objects with named > > > parameters" ); > > > query.getResultList(); > > > > > > If it helps, the objects queried are of type AddShapeCommand, which is > > > part of a three-level object hierarchy: Command -> ShapeCommand -> > > > AddShapeCommand. I also include the annotations related to > > > inheritance: > > > > > > @Entity > > > @Table( name="command" ) > > > @Inheritance( strategy=InheritanceType.SINGLE_TABLE ) > > > @DiscriminatorColumn( name="command_type", > > > discriminatorType=DiscriminatorType.INTEGER ) > > > @DiscriminatorValue( "0" ) > > > public class Command > > > { > > > ... > > > } > > > > > > @MappedSuperclass > > > public abstract class ShapeCommand extends Command > > > { > > > ... > > > } > > > > > > @Entity > > > @DiscriminatorValue( "2" ) > > > public class AddShapeCommand extends ShapeCommand > > > { > > > .. > > > } > > > > > > Christian > > > > > > On 8/23/07, Patrick Linskey wrote: > > > > Hi, > > > > > > > > Can you post a thread dump from the deadlock? > > > > > > > > My guess would be that we're using the second connection to fetch an > > > > ID value from a sequence table. Otherwise, we should not be obtaining > > > > multiple. > > > > > > > > -Patrick > > > > > > > > On 8/23/07, Christian Defoy wrote: > > > > > Hello, > > > > > > > > > > Quick question about connection usage: > > > > > > > > > > I was performing some tests and I noticed that my connection pool was > > > > > configured for 10 connections but theoretically, I should need only > > > > > one so I set the connection pool size to 1. Now, my application > > > > > deadlocks because it appears that getEntityManager() requests a > > > > > connection and query.getResultList() requests one too. > > > > > > > > > > When I read section 4.8 "Configuring the Use of JDBC Connections", I > > > > > thought that setting openjpa.ConnectionRetainMode to "always" would > > > > > have the entity manager retain its connection (that part works fine) > > > > > but that it would have the entity manager share that connection with > > > > > queries... > > > > > > > > > > Is there a way to make that happen? My server is kind of counting on > > > > > the fact that a single connection is used to process a single > > > > > request... > > > > > > > > > > Christian > > > > > > > > > > > > > > > > > -- > > > > Patrick Linskey > > > > 202 669 5907 > > > > > > > > > > > > > -- > > Patrick Linskey > > 202 669 5907 > > > -- Patrick Linskey 202 669 5907