cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrus Adamchik (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (CAY-1725) NullPointerException from call to removeToManyTarget
Date Fri, 13 Jul 2012 19:15:35 GMT

    [ https://issues.apache.org/jira/browse/CAY-1725?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13413967#comment-13413967
] 

Andrus Adamchik edited comment on CAY-1725 at 7/13/12 7:14 PM:
---------------------------------------------------------------

I tried it with 3.1 and with an entirely different database, Derby in this case. And I can
reproduce it... Interestingly the underlying cause is a swallowed exception running SQLTemplate
inside FlattenedArcKey. SQL generated from SelectQuery for instance, uses quotations:

SELECT "t0"."id", "t0"."name" FROM "Department" "t0"

While SQLTemplate built by FlattenedArcKey does not:

SELECT id FROM Authorization WHERE approverId = ? AND departmentId = ? [bind: 1:1, 2:1]

Which results in a DB error:

INFO: *** error.
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "Authorization" at line 1, column
16.
	at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
       ...
      	at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
	at org.apache.cayenne.conn.ConnectionWrapper.prepareStatement(ConnectionWrapper.java:282)
	at org.apache.cayenne.conn.ConnectionWrapper.prepareStatement(ConnectionWrapper.java:288)
	at org.apache.cayenne.access.TransactionConnectionDecorator.prepareStatement(TransactionConnectionDecorator.java:187)
	at org.apache.cayenne.access.jdbc.SQLTemplateAction.execute(SQLTemplateAction.java:145)
	at org.apache.cayenne.access.jdbc.SQLTemplateAction.performAction(SQLTemplateAction.java:124)
	at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:87)
	at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:280)
	at org.apache.cayenne.access.FlattenedArcKey.buildJoinSnapshotsForDelete(FlattenedArcKey.java:198)

I assume "Authorization" is a SQL keyword, so when used unquoted it blows the query parser.
Also very not like the rest of Cayenne, Exception is not propagated to the caller, but rather
swallowed because SQLtemplate is run directly against the DataNode (very low level code that
is never called directly... all exception unwinding sits above it in Cayenne)... 

Looking for a fix now... 


                
      was (Author: andrus):
    I tried it with 3.1 and with an entirely different database, Derby in this case. And I
can reproduce it... Interestingly the underlying cause is a swallowed exception running SQLTemplate
inside FlattenedArcKey. SQL generated from SelectQuery for instance, uses quotations:

SELECT "t0"."id", "t0"."name" FROM "Department" "t0"

While SQLTemplate built by FlattenedArcKey does not:

SELECT id FROM Authorization WHERE approverId = ? AND departmentId = ? [bind: 1:1, 2:1]

Which results in a DB error:

INFO: *** error.
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "Authorization" at line 1, column
16.
	at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)

I assume "Authorization" is a SQL keyword, so when used unquoted it blows the query parser.
Also very not like the rest of Cayenne, Exception is not propagated to the caller, but rather
swallowed because SQLtemplate is run directly against the DataNode (very low level code that
is never called directly... all exception unwinding sits above it in Cayenne)... 

Looking for a fix now... 


                  
> NullPointerException from call to removeToManyTarget
> ----------------------------------------------------
>
>                 Key: CAY-1725
>                 URL: https://issues.apache.org/jira/browse/CAY-1725
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.1, 3.0.2
>            Reporter: Aaron Andersen
>         Attachments: KeysDomainNode.driver.xml, KeysMap.map.xml, cayenne.xml
>
>
> I am using Cayenne version 3.0.1.
> In CayenneModeler I have created an "Approver" DbEntity and a "Department" DbEntity (as
well as the corresponding ObjEntity classes). I have also created an "Authorization" DbEntity
to act as a join table for the Approver and Department tables. Every Approver object has a
list of Department objects associated with it, and vice versa so in CayenneModeler I have
added a "departmentArray" relationship to the Approver object which has "to many, list" semantics.
> When I use the Approver method "void addToDepartmentArray (Department)" everything works
fine, but when I use the Approver method "void removeFromDepartmentArray (Department)" (which
simple calls removeToManyTarget) a NullPointerException is thrown. A backtrace and quick debug
tells me the null pointer exception originates from:
> org.apache.cayenne.access.DataDomainFlattenedBucket.addFlattenedDelete(DataDomainFlattenedBucket.java:82)
> The code on lines 81 and 82 of this file are as follows:
> [81] List flattenedSnapshots = flattenedDeleteInfo.buildJoinSnapshotsForDelete(node);
> [82] if (!flattenedSnapshots.isEmpty()) {
> Inspecting flattenedSnapshots on line 82 shows that flattenedSnapshots is null hence
accessing the isEmpty method is causing the null pointer exception.
> I have also tested with Cayenne 3.0.2 and the same error occurs.
> Here is a simple code snippet to reproduce this error:
> // make sure our context is clear of any changes
> context.rollbackChanges ();
> // set up a new approver and department
> Approver approver = context.newObject (Approver.class);
> Department dept = context.newObject (Department.class);
> approver.setLogin ("approver");
> dept.setName ("departmentA");
> // add the department to the approver
> approver.addToDepartmentArray (dept);
> // commit these to the database, so far everything should be running fine
> context.commitChanges ();
> // remove the department from the approver... 
> // this should work fine because we haven't committed yet
> approver.removeFromDepartmentArray (dept);
> try {
>     // this is where things go bad
>     context.commitChanges ();
> } catch (Exception e) {
>     // error has occurred
>     // at this point the record in the Authorization table still exists
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message