openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrick Linskey" <plins...@gmail.com>
Subject Re: Connection usage
Date Fri, 24 Aug 2007 01:19:38 GMT
> I still get stuck at the getResultList() call as it tries to get a
> connection (same as before).

Yeah, I was afraid that that might be the case.

> Do I define foreign keys in my annotations using
> org.apache.openjpa.persistence.jdbc.ForeignKey?

Yes.

-Patrick

On 8/23/07, Christian Defoy <christian.defoy@gmail.com> wrote:
> If I do:
>
> factory.createEntityManager().close();
> manager = factory.createEntityManager();
> Query query = manager.createQuery( "some query" );
> query.getResultList();
>
> I still get stuck at the getResultList() call as it tries to get a
> connection (same as before).
>
>
> Do I define foreign keys in my annotations using
> org.apache.openjpa.persistence.jdbc.ForeignKey?
>
> Christian
>
>
>
> On 8/23/07, Patrick Linskey <plinskey@gmail.com> wrote:
> > 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 <christian.defoy@gmail.com> wrote:
> > > I found the problem...
> > >
> > > <property name="openjpa.jdbc.SchemaFactory" value="native(ForeignKeys=true)"
/>
> > >
> > > 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).
> > >
> > > <class>ex5.Command</class>
> > > <class>ex5.ShapeCommand</class>
> > > <class>ex5.AddShapeCommand</class>
> > >
> > > 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 <plinskey@gmail.com> 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 <christian.defoy@gmail.com> 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 <plinskey@gmail.com> 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 <christian.defoy@gmail.com>
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
> >
>


-- 
Patrick Linskey
202 669 5907

Mime
View raw message