FAQ
Hi,
I have a very strange problem with Cayenne 3.0 and Derby Embedded database.
When i execute my application, first runs a query, then when runs the second
one (different from first), it raise this exception:

Exception in thread "Thread-5" org.apache.cayenne.CayenneRuntimeException:
[v.3.0 Apr 26 2010 09:59:17] Global exception.
at
org.apache.cayenne.access.DataDomainQueryAction.nextGlobalException(DataDomainQueryAction.java:553)
at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:258)
at
org.apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQueryAction.java:422)
at
org.apache.cayenne.access.DataDomainQueryAction.access$000(DataDomainQueryAction.java:69)
at
org.apache.cayenne.access.DataDomainQueryAction$2.transform(DataDomainQueryAction.java:395)
at
org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:840)
at
org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(DataDomainQueryAction.java:392)
at
org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:121)
at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:743)
at
org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:333)
at
org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:96)
at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1278)
at org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1267)
at minica.server.actions.CANewCertAction.doAction(CANewCertAction.java:46)
at
minica.server.parsers.CANewCertParser.parseMessage(CANewCertParser.java:37)
at minica.server.CASocketReceiver.run(CASocketReceiver.java:73)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.IllegalStateException: Transaction must have
'STATUS_ACTIVE' to add a connection. Current status: STATUS_COMMITTED
at
org.apache.cayenne.access.ExternalTransaction.addConnection(ExternalTransaction.java:64)
at
org.apache.cayenne.access.DataNode$TransactionDataSource.getConnection(DataNode.java:365)
at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:248)
... 15 more

The second query is executed in a different thread.
This is a code I use to get the DataContext object:

public ObjectContext getContext() {
try {
return BaseContext.getThreadObjectContext();
} catch(IllegalStateException e) {

BaseContext.bindThreadObjectContext(DataContext.createDataContext(false));
return BaseContext.getThreadObjectContext();
}
}

Both queries are simply SelectQuery:

1.
ObjectContext context =
CertificationAuthority.getInstance().getContext();
SelectQuery select1 = new SelectQuery(DBCertificate.class);
List<DBCertificate> l = context.performQuery(select1);

2.
ObjectContext context =
CertificationAuthority.getInstance().getContext();
Expression clause = ExpressionFactory.matchExp(DBUser.NAME_PROPERTY,
subject);
SelectQuery query = new SelectQuery(DBUser.class, clause);
List<DBUser> result = context.performQuery(query);

The very strange thing is that the app raises exception only at first time,
when DB is empty and, more strange, if I execute in debug mode, all works
well !
I try anything but I don't find any solution.

Any suggestions?

*Andrea*

Search Discussions

  • Andrea Pavan at Jun 8, 2010 at 7:54 pm
    Hi,
    I have a very strange problem with Cayenne 3.0 and Derby Embedded database.
    When i execute my application, first runs a query, then when runs the second
    one (different from first), it raise this exception:

    Exception in thread "Thread-5" org.apache.cayenne.CayenneRuntimeException:
    [v.3.0 Apr 26 2010 09:59:17] Global exception.
    at
    org.apache.cayenne.access.DataDomainQueryAction.nextGlobalException(DataDomainQueryAction.java:553)
    at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:258)
    at
    org.apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQueryAction.java:422)
    at
    org.apache.cayenne.access.DataDomainQueryAction.access$000(DataDomainQueryAction.java:69)
    at
    org.apache.cayenne.access.DataDomainQueryAction$2.transform(DataDomainQueryAction.java:395)
    at
    org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:840)
    at
    org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(DataDomainQueryAction.java:392)
    at
    org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:121)
    at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:743)
    at
    org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:333)
    at
    org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:96)
    at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1278)
    at org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1267)
    at minica.server.actions.CANewCertAction.doAction(CANewCertAction.java:46)
    at
    minica.server.parsers.CANewCertParser.parseMessage(CANewCertParser.java:37)
    at minica.server.CASocketReceiver.run(CASocketReceiver.java:73)
    at java.lang.Thread.run(Thread.java:619)
    Caused by: java.lang.IllegalStateException: Transaction must have
    'STATUS_ACTIVE' to add a connection. Current status: STATUS_COMMITTED
    at
    org.apache.cayenne.access.ExternalTransaction.addConnection(ExternalTransaction.java:64)
    at
    org.apache.cayenne.access.DataNode$TransactionDataSource.getConnection(DataNode.java:365)
    at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:248)
    ... 15 more

    The second query is executed in a different thread.
    This is a code I use to get the DataContext object:

    public ObjectContext getContext() {
    try {
    return BaseContext.getThreadObjectContext();
    } catch(IllegalStateException e) {

    BaseContext.bindThreadObjectContext(DataContext.createDataContext(false));
    return BaseContext.getThreadObjectContext();
    }
    }

    Both queries are simply SelectQuery:

    1.
    ObjectContext context =
    CertificationAuthority.getInstance().getContext();
    SelectQuery select1 = new SelectQuery(DBCertificate.class);
    List<DBCertificate> l = context.performQuery(select1);

    2.
    ObjectContext context =
    CertificationAuthority.getInstance().getContext();
    Expression clause = ExpressionFactory.matchExp(DBUser.NAME_PROPERTY,
    subject);
    SelectQuery query = new SelectQuery(DBUser.class, clause);
    List<DBUser> result = context.performQuery(query);

    The very strange thing is that the app raises exception only at first time,
    when DB is empty and, more strange, if I execute in debug mode, all works
    well !
    I try anything but I don't find any solution.

    Any suggestions?

    *Andrea*
  • Andrea Pavan at Jun 8, 2010 at 8:32 pm
    Sorry for double post, it's my first time :)
    Anyway, I solve the problem using H2 instead of Derby and, for now, all
    works like a charm!

    2010/6/8 Andrea Pavan <prog.pawz@gmail.com>
    Hi,
    I have a very strange problem with Cayenne 3.0 and Derby Embedded database.
    When i execute my application, first runs a query, then when runs the
    second one (different from first), it raise this exception:

    Exception in thread "Thread-5" org.apache.cayenne.CayenneRuntimeException:
    [v.3.0 Apr 26 2010 09:59:17] Global exception.
    at
    org.apache.cayenne.access.DataDomainQueryAction.nextGlobalException(DataDomainQueryAction.java:553)
    at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:258)
    at
    org.apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQueryAction.java:422)
    at
    org.apache.cayenne.access.DataDomainQueryAction.access$000(DataDomainQueryAction.java:69)
    at
    org.apache.cayenne.access.DataDomainQueryAction$2.transform(DataDomainQueryAction.java:395)
    at
    org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:840)
    at
    org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(DataDomainQueryAction.java:392)
    at
    org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:121)
    at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:743)
    at
    org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:333)
    at
    org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:96)
    at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1278)
    at
    org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1267)
    at
    minica.server.actions.CANewCertAction.doAction(CANewCertAction.java:46)
    at
    minica.server.parsers.CANewCertParser.parseMessage(CANewCertParser.java:37)
    at minica.server.CASocketReceiver.run(CASocketReceiver.java:73)
    at java.lang.Thread.run(Thread.java:619)
    Caused by: java.lang.IllegalStateException: Transaction must have
    'STATUS_ACTIVE' to add a connection. Current status: STATUS_COMMITTED
    at
    org.apache.cayenne.access.ExternalTransaction.addConnection(ExternalTransaction.java:64)
    at
    org.apache.cayenne.access.DataNode$TransactionDataSource.getConnection(DataNode.java:365)
    at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:248)
    ... 15 more

    The second query is executed in a different thread.
    This is a code I use to get the DataContext object:

    public ObjectContext getContext() {
    try {
    return BaseContext.getThreadObjectContext();
    } catch(IllegalStateException e) {

    BaseContext.bindThreadObjectContext(DataContext.createDataContext(false));
    return BaseContext.getThreadObjectContext();
    }
    }

    Both queries are simply SelectQuery:

    1.
    ObjectContext context =
    CertificationAuthority.getInstance().getContext();
    SelectQuery select1 = new SelectQuery(DBCertificate.class);
    List<DBCertificate> l = context.performQuery(select1);

    2.
    ObjectContext context =
    CertificationAuthority.getInstance().getContext();
    Expression clause = ExpressionFactory.matchExp(DBUser.NAME_PROPERTY,
    subject);
    SelectQuery query = new SelectQuery(DBUser.class, clause);
    List<DBUser> result = context.performQuery(query);

    The very strange thing is that the app raises exception only at first time,
    when DB is empty and, more strange, if I execute in debug mode, all works
    well !
    I try anything but I don't find any solution.

    Any suggestions?

    *Andrea*
  • Andrus Adamchik at Jun 8, 2010 at 8:47 pm
    This seems like a race condition, and I am not sure that switching the
    DB fixes it. I just don't understand how it can possibly happen. Do
    you have "Container Managed Transactions" set to on by any chance?

    Andrus
    On Jun 8, 2010, at 1:26 PM, Andrea Pavan wrote:

    Sorry for double post, it's my first time :)
    Anyway, I solve the problem using H2 instead of Derby and, for now,
    all
    works like a charm!

    2010/6/8 Andrea Pavan <prog.pawz@gmail.com>
    Hi,
    I have a very strange problem with Cayenne 3.0 and Derby Embedded
    database.
    When i execute my application, first runs a query, then when runs the
    second one (different from first), it raise this exception:

    Exception in thread "Thread-5"
    org.apache.cayenne.CayenneRuntimeException:
    [v.3.0 Apr 26 2010 09:59:17] Global exception.
    at
    org
    .apache
    .cayenne
    .access
    .DataDomainQueryAction
    .nextGlobalException(DataDomainQueryAction.java:553)
    at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:
    258)
    at
    org
    .apache
    .cayenne
    .access.DataDomainQueryAction.runQuery(DataDomainQueryAction.java:
    422)
    at
    org.apache.cayenne.access.DataDomainQueryAction.access
    $000(DataDomainQueryAction.java:69)
    at
    org.apache.cayenne.access.DataDomainQueryAction
    $2.transform(DataDomainQueryAction.java:395)
    at
    org
    .apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:
    840)
    at
    org
    .apache
    .cayenne
    .access
    .DataDomainQueryAction
    .runQueryInTransaction(DataDomainQueryAction.java:392)
    at
    org
    .apache
    .cayenne
    .access.DataDomainQueryAction.execute(DataDomainQueryAction.java:121)
    at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:743)
    at
    org
    .apache
    .cayenne
    .util
    .ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:333)
    at
    org
    .apache
    .cayenne
    .util
    .ObjectContextQueryAction.execute(ObjectContextQueryAction.java:96)
    at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:
    1278)
    at
    org.apache.cayenne.access.DataContext.performQuery(DataContext.java:
    1267)
    at
    minica.server.actions.CANewCertAction.doAction(CANewCertAction.java:
    46)
    at
    minica
    .server.parsers.CANewCertParser.parseMessage(CANewCertParser.java:37)
    at minica.server.CASocketReceiver.run(CASocketReceiver.java:73)
    at java.lang.Thread.run(Thread.java:619)
    Caused by: java.lang.IllegalStateException: Transaction must have
    'STATUS_ACTIVE' to add a connection. Current status: STATUS_COMMITTED
    at
    org
    .apache
    .cayenne
    .access.ExternalTransaction.addConnection(ExternalTransaction.java:
    64)
    at
    org.apache.cayenne.access.DataNode
    $TransactionDataSource.getConnection(DataNode.java:365)
    at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:
    248)
    ... 15 more

    The second query is executed in a different thread.
    This is a code I use to get the DataContext object:

    public ObjectContext getContext() {
    try {
    return BaseContext.getThreadObjectContext();
    } catch(IllegalStateException e) {

    BaseContext
    .bindThreadObjectContext(DataContext.createDataContext(false));
    return BaseContext.getThreadObjectContext();
    }
    }

    Both queries are simply SelectQuery:

    1.
    ObjectContext context =
    CertificationAuthority.getInstance().getContext();
    SelectQuery select1 = new SelectQuery(DBCertificate.class);
    List<DBCertificate> l = context.performQuery(select1);

    2.
    ObjectContext context =
    CertificationAuthority.getInstance().getContext();
    Expression clause =
    ExpressionFactory.matchExp(DBUser.NAME_PROPERTY,
    subject);
    SelectQuery query = new SelectQuery(DBUser.class, clause);
    List<DBUser> result = context.performQuery(query);

    The very strange thing is that the app raises exception only at
    first time,
    when DB is empty and, more strange, if I execute in debug mode, all
    works
    well !
    I try anything but I don't find any solution.

    Any suggestions?

    *Andrea*
  • Andrea Pavan at Jun 9, 2010 at 4:39 am
    No, "Container Managed Transactions" isn't checked.

    2010/6/8 Andrus Adamchik <andrus@objectstyle.org>
    This seems like a race condition, and I am not sure that switching the DB
    fixes it. I just don't understand how it can possibly happen. Do you have
    "Container Managed Transactions" set to on by any chance?

    Andrus
  • Andrea Pavan at Jun 9, 2010 at 7:24 am
    As you said, the problem persist also with H2, even if it happens many time
    less, maybe because H2 executes queries faster.
    I synchronized the method for obtaining the thread bounded DataContext, but
    the problem still persist.
    Have I to synchronize also the method that creates and performs query?

    Thanks for help.

    *Andrea*

    2010/6/9 Andrea Pavan <prog.pawz@gmail.com>
    No, "Container Managed Transactions" isn't checked.

    2010/6/8 Andrus Adamchik <andrus@objectstyle.org>

    This seems like a race condition, and I am not sure that switching the DB
    fixes it. I just don't understand how it can possibly happen. Do you have
    "Container Managed Transactions" set to on by any chance?

    Andrus
  • Andrus Adamchik at Jun 9, 2010 at 5:07 pm
    Actually no, and this is what makes it so strange. DataContext is
    thread-safe for read operations, so multiple threads can access it
    simultaneously. Transactions are bound to threads, and unbound in the
    finally block, so overlapping transactions between threads should not
    be possible, neither are overlapping transactions within a thread.

    So anything else special/customized about your transactions? In any
    event In recommend running your app in debugger and putting a
    breakpoint in DataDomain.runInTransaction(..) to check what really
    happens.

    Andrus
    On Jun 9, 2010, at 12:23 AM, Andrea Pavan wrote:

    As you said, the problem persist also with H2, even if it happens
    many time
    less, maybe because H2 executes queries faster.
    I synchronized the method for obtaining the thread bounded
    DataContext, but
    the problem still persist.
    Have I to synchronize also the method that creates and performs query?

    Thanks for help.

    *Andrea*

    2010/6/9 Andrea Pavan <prog.pawz@gmail.com>
    No, "Container Managed Transactions" isn't checked.

    2010/6/8 Andrus Adamchik <andrus@objectstyle.org>

    This seems like a race condition, and I am not sure that switching
    the DB
    fixes it. I just don't understand how it can possibly happen. Do
    you have
    "Container Managed Transactions" set to on by any chance?

    Andrus

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedJun 8, '10 at 7:49p
activeJun 9, '10 at 5:07p
posts7
users2
websitecayenne.apache.org

2 users in discussion

Andrea Pavan: 5 posts Andrus Adamchik: 2 posts

People

Translate

site design / logo © 2022 Grokbase