FAQ
Hi, I wrote code to clone a DataMap, appending a suffix to the Entities
to avoid name collisions (in this instance I am not cloning the
relationships). After adding the cloned DataMap to the data node, I can
successfully commit transactions to the dynamically-generated tables. I
can also query for all of the objects in the tables (they are
CayenneDataObjects, since I can't generate new Java classes
dynamically).



However, when I create a SelectQuery given the DbEntity and an
Expression, where the expression is
ExpressionFactory.matchEquals(MaritalStatus.DESCRIPTION_PROPERTY,
"Married"), and call DataContext.performQuery(), I get a
NullPointerException here:

java.lang.NullPointerException

at
org.apache.cayenne.access.trans.QueryAssemblerHelper.appendObjPath(Query
AssemblerHelper.java:141)

at
org.apache.cayenne.access.trans.QualifierTranslator.objectNode(Qualifier
Translator.java:376)

at
org.apache.cayenne.exp.Expression.traverse(Expression.java:464)

at
org.apache.cayenne.exp.Expression.traverse(Expression.java:461)

at
org.apache.cayenne.exp.Expression.traverse(Expression.java:441)

at
org.apache.cayenne.access.trans.QualifierTranslator.doAppendPart(Qualifi
erTranslator.java:76)

at
org.apache.cayenne.access.trans.QualifierTranslator.doAppendPart(Qualifi
erTranslator.java:65)

at
org.apache.cayenne.access.trans.QueryAssemblerHelper.appendPart(QueryAss
emblerHelper.java:83)

at
org.apache.cayenne.access.trans.SelectTranslator.createSqlString(SelectT
ranslator.java:130)

at
org.apache.cayenne.access.trans.QueryAssembler.createStatement(QueryAsse
mbler.java:194)

at
org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.j
ava:70)

at
org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryActi
on.java:87)

at
org.apache.cayenne.access.DataNode.performQueries(DataNode.java:269)

at
org.apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQuery
Action.java:422)

at
org.apache.cayenne.access.DataDomainQueryAction.access$000(DataDomainQue
ryAction.java:69)

at
org.apache.cayenne.access.DataDomainQueryAction$2.transform(DataDomainQu
eryAction.java:395)

at
org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:85
0)

at
org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(Da
taDomainQueryAction.java:392)

at
org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryA
ction.java:121)

at
org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:743)

at
org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQ
ueryAction.java:333)

at
org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQu
eryAction.java:96)

at
org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1278)

at
org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1267
)



At the QueryAssemblerHelper.appendObjPath() line:

for (PathComponent<ObjAttribute, ObjRelationship> component :
getObjEntity()



because getObjEntity() returns null because the query's classDescriptor
is null.



When I clone the DataMap, do I need to create a ClassDescriptor for each
ObjEntity? If so, is that possible for dynamic ObjEntity's which don't
have a real corresponding Java class?



Thanks,

Joel

Search Discussions

  • Becker, Joel at Nov 4, 2011 at 8:21 pm
    I worked around it by creating a SelectQuery based on the cloned
    DataMap's ObjEntity rather than DbEntity.



    From: Becker, Joel
    Sent: Friday, November 04, 2011 2:16 PM
    To: 'user@cayenne.apache.org'
    Subject: Clone and modify DataMap - NullPointerException with
    SelectQuery with Expression



    Hi, I wrote code to clone a DataMap, appending a suffix to the Entities
    to avoid name collisions (in this instance I am not cloning the
    relationships). After adding the cloned DataMap to the data node, I can
    successfully commit transactions to the dynamically-generated tables. I
    can also query for all of the objects in the tables (they are
    CayenneDataObjects, since I can't generate new Java classes
    dynamically).



    However, when I create a SelectQuery given the DbEntity and an
    Expression, where the expression is
    ExpressionFactory.matchEquals(MaritalStatus.DESCRIPTION_PROPERTY,
    "Married"), and call DataContext.performQuery(), I get a
    NullPointerException here:

    java.lang.NullPointerException

    at
    org.apache.cayenne.access.trans.QueryAssemblerHelper.appendObjPath(Query
    AssemblerHelper.java:141)

    at
    org.apache.cayenne.access.trans.QualifierTranslator.objectNode(Qualifier
    Translator.java:376)

    at
    org.apache.cayenne.exp.Expression.traverse(Expression.java:464)

    at
    org.apache.cayenne.exp.Expression.traverse(Expression.java:461)

    at
    org.apache.cayenne.exp.Expression.traverse(Expression.java:441)

    at
    org.apache.cayenne.access.trans.QualifierTranslator.doAppendPart(Qualifi
    erTranslator.java:76)

    at
    org.apache.cayenne.access.trans.QualifierTranslator.doAppendPart(Qualifi
    erTranslator.java:65)

    at
    org.apache.cayenne.access.trans.QueryAssemblerHelper.appendPart(QueryAss
    emblerHelper.java:83)

    at
    org.apache.cayenne.access.trans.SelectTranslator.createSqlString(SelectT
    ranslator.java:130)

    at
    org.apache.cayenne.access.trans.QueryAssembler.createStatement(QueryAsse
    mbler.java:194)

    at
    org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.j
    ava:70)

    at
    org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryActi
    on.java:87)

    at
    org.apache.cayenne.access.DataNode.performQueries(DataNode.java:269)

    at
    org.apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQuery
    Action.java:422)

    at
    org.apache.cayenne.access.DataDomainQueryAction.access$000(DataDomainQue
    ryAction.java:69)

    at
    org.apache.cayenne.access.DataDomainQueryAction$2.transform(DataDomainQu
    eryAction.java:395)

    at
    org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:85
    0)

    at
    org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(Da
    taDomainQueryAction.java:392)

    at
    org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryA
    ction.java:121)

    at
    org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:743)

    at
    org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQ
    ueryAction.java:333)

    at
    org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQu
    eryAction.java:96)

    at
    org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1278)

    at
    org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1267
    )



    At the QueryAssemblerHelper.appendObjPath() line:

    for (PathComponent<ObjAttribute, ObjRelationship> component :
    getObjEntity()



    because getObjEntity() returns null because the query's classDescriptor
    is null.



    When I clone the DataMap, do I need to create a ClassDescriptor for each
    ObjEntity? If so, is that possible for dynamic ObjEntity's which don't
    have a real corresponding Java class?



    Thanks,

    Joel

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedNov 4, '11 at 7:16p
activeNov 4, '11 at 8:21p
posts2
users1
websitecayenne.apache.org

1 user in discussion

Becker, Joel: 2 posts

People

Translate

site design / logo © 2022 Grokbase