Re: Attempt to generate SQL failed
Re: Attempt to generate SQL failed
- Subject: Re: Attempt to generate SQL failed
- From: Ian Joyner <email@hidden>
- Date: Fri, 16 Sep 2005 12:07:19 +1000
On 16/09/2005, at 7:00 AM, Guido Neitzer wrote:
There is another bug on that, if I remember correctly: if you add
an attribute to the base class, it is added to the subclasses, but
not checked to be a class property ... (Don't have this good enough
in my memory to describe it better or to be sure about it.)
Yes EOModeler does seem to have the annoying habit of resetting the
client-side property when you are not looking (making changes in the
inspector panel). However, I did make sure they were all checked. I
have just submitted the following report to Apple (bug 4260198)
16-Sep-2005 12:02 PM Ian Joyner:
Summary:
A relationship from one entity to a second entity that has subclasses
causes an 'Unable to generate SQL' error.
Steps to Reproduce:
Create an entity A that has a relationship to an entity T with
subclass entities TR and TS using horizontal inheritance. T is
abstract (although it doesn't seem to need to be). Adding records of
type TR and TS generate SQL fine, but entity A has a line to update
its modification date:
public void awakeFromClientUpdate (EOEditingContext ec) {
super.awakeFromClientUpdate (ec);
setModification_date (new NSTimestamp ());
}
A has the one-to-many relationship ts A(primary_key) -> T (a_key)
and
T has the to-one relationship a T(a_key) -> A(primary_key)
which is inherited (and duplicated by showing in italics in
EOModeler) by TR and TS.
A T object is initialized as follows:
public void initialize (A for_a) {
setA (for_a);
addObjectToBothSidesOfRelationshipWithKey (for_a, "a");
}
However, the setModification_date line in awakeFromClientUpdate
causes the following failure:
[2005-09-14 16:43:39 EST] <WorkerThread11> evaluateExpression:
<com.webobjects.jdbcadaptor.OpenBasePlugIn$OpenBaseExpression:
"INSERT INTO TR(A_KEY, NOTES, GRADE_KEY, PRIMARY_KEY,
PARENT_TEST_KEY, TEST_KEY, DATE) VALUES (?, NULL, ?, ?, ?, ?, ?)"
withBindings: 1:5(a_key), 2:5(grade_key), 3:129(primary_key), 4:133
(parent_test_key), 5:19(test_key), 6:2005-09-14 16:43:17(date)>
[2005-09-14 16:43:39 EST] <WorkerThread11> === Rollback Internal
Transaction
[2005-09-14 16:43:39 EST] <WorkerThread11> Server exception:
sqlStringForKeyValueQualifier: attempt to generate SQL for
com.webobjects.eocontrol.EOKeyValueQualifier (NeededByEOF0 = 5)
failed because attribute identified by key 'NeededByEOF0' was not
reachable from from entity 'A'
[2005-09-14 16:43:39 EST] <WorkerThread11>
com.webobjects.eoaccess.EOGeneralAdaptorException:
sqlStringForKeyValueQualifier: attempt to generate SQL for
com.webobjects.eocontrol.EOKeyValueQualifier (NeededByEOF0 = 5)
failed because attribute identified by key 'NeededByEOF0' was not
reachable from from entity 'A'
at
com.webobjects.eoaccess.EODatabaseContext._exceptionWithDatabaseContextI
nformationAdded(EODatabaseContext.java:4686)
at com.webobjects.eoaccess.EODatabaseContext.performChanges
(EODatabaseContext.java:6394)
at
com.webobjects.eocontrol.EOObjectStoreCoordinator.saveChangesInEditingCo
ntext(EOObjectStoreCoordinator.java:415)
at com.webobjects.eocontrol.EOEditingContext.saveChanges
(EOEditingContext.java:3187)
at com.webobjects.eodistribution.EODistributionContext
$_RemoteMethodReceiver.clientSideRequestSave
(EODistributionContext.java:1071)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Note that the TR records have been inserted correctly and the SQL
being generated is for the update of the A record.
Expected Results:
SQL to update A should have been generated and executed.
Actual Results:
com.webobjects.eoaccess.EOGeneralAdaptorException:
sqlStringForKeyValueQualifier: attempt to generate SQL for
com.webobjects.eocontrol.EOKeyValueQualifier (NeededByEOF0 = 5)
failed because attribute identified by key 'NeededByEOF0' was not
reachable from from entity 'A'
Regression:
This error occurs on 5.2.4 using Java Client and Interface Builder,
any hardware configuration.
Notes:
The workaround was to replace the relationship t to T with
relationships tr and ts to the subclasses TR and TS and to build the
display array for all T records from TR union TS.
cug
On 15.09.2005, at 20:03 Uhr, Chuck Hill wrote:
Looks like maybe missing back pointing relationships. Adding
relationships to base classes after subclasses have been created
does not add them to the subclasses (EOModeler bug).
Chuck
On Sep 14, 2005, at 6:48 PM, Ian Joyner wrote:
Here's something else puzzling about my problem. If I add
something else attached to Asset, then do the save, it updates
the Test_results fine and updates the Person (parent class of
Asset) setting the modification date. The interesting thing is
that in the Person update, it uses 'NeededByEOF0' to set the
binding for PRIMARY_KEY:
[2005-09-15 11:37:57 EST] <WorkerThread7> evaluateExpression:
<com.webobjects.jdbcadaptor.OpenBasePlugIn$OpenBaseExpression:
"INSERT INTO BODY_METRICS(ASSET_KEY, NOTES, LEG_LENGTH,
PRIMARY_KEY, THIGH_MEASURE, BICEP_MEASURE, HEIGHT, PROTOCOL,
ARM_LENGTH, DATE, WAIST) VALUES (?, NULL, ?, ?, ?, ?, ?,
NULL, ?, ?, ?)" withBindings: 1:5(asset_key), 2:0(leg_length), 3:4
(primary_key), 4:0(thigh_measure), 5:0(bicep_measure), 6:0
(height), 7:0(arm_length), 8:2005-09-15 11:37:53(date), 9:0(waist)>
[2005-09-15 11:37:57 EST] <WorkerThread7> evaluateExpression:
<com.webobjects.jdbcadaptor.OpenBasePlugIn$OpenBaseExpression:
"UPDATE PERSON SET MODIFICATION_DATE = ? WHERE (PRIMARY_KEY = ?
AND UNIQUE_ID is NULL AND TYPE = ? AND TITLE_KEY = ? AND
TERMINATION_DATE is NULL AND SURNAME = ? AND PERSON_TYPE_KEY = ?
AND MODIFICATION_DATE = ? AND MIDDLE_NAMES is NULL AND GENDER_KEY
= ? AND FIRST_NAME = ? AND DATE_OF_BIRTH is NULL AND
CREATION_DATE = ? AND ALIAS = ?)" withBindings: 1:2005-09-15
11:37:57(modification_date), 2:5(NeededByEOF0), 3:"A"(type), 4:1
(title_key), 5:"Lincoln"(surname), 6:12(person_type_key),
7:2005-09-15 10:33:41(modification_date), 8:6(gender_key),
9:"Abraham"(first_name), 10:2005-09-14 15:40:09(creation_date),
11:"Abe"(alias)>
Can anyone give any direction as to what to check to fix this?
Thanks
Ian
On 14/09/2005, at 5:19 PM, Ian Joyner wrote:
I have just managed to break some code which has been working
for some time. I have narrowed it down to a line on the server
side as follows:
public void awakeFromClientUpdate (EOEditingContext ec) {
super.awakeFromClientUpdate (ec);
// setModification_date (new NSTimestamp ());
}
The commented out line causes the failure, and what has happened
is that I have added a set of 'test' (not programming tests)
entities which get attached to an Asset entity. So Asset sees
its Test_results from a one-to-many relationship:
test_results: Asset (primary_key) --> Test_result (asset_key)
Now Test_result is abstract and has subclasses Graded_result and
Value_result. I add a set of these, setting their asset_key (in
class Test_result) as follows:
public void initialize (Skills_test its_test, Asset
for_asset, Test_result parent_result) {
setTest (its_test);
setAsset (for_asset);
addObjectToBothSidesOfRelationshipWithKey (for_asset,
"asset");
for_asset.addObjectToBothSidesOfRelationshipWithKey
(this, "test_results");
setParent_test (parent_result);
setDate (new NSTimestamp ());
}
I should only need one
addObjectToBothSidesOfRelationshipWithKey, but I tried both
combinations just to make sure.
When I do an editingContext.saveChanges (), all of the
Graded_results are stored fine, but the last thing it tries to
do is to update the modification date on Asset, but at this
point I get:
[2005-09-14 16:43:39 EST] <WorkerThread11> evaluateExpression:
<com.webobjects.jdbcadaptor.OpenBasePlugIn$OpenBaseExpression:
"INSERT INTO GRADED_TEST_RESULT(ASSET_KEY, NOTES, GRADE_KEY,
PRIMARY_KEY, PARENT_TEST_KEY, TEST_KEY, DATE) VALUES (?,
NULL, ?, ?, ?, ?, ?)" withBindings: 1:5(asset_key), 2:5
(grade_key), 3:129(primary_key), 4:133(parent_test_key), 5:19
(test_key), 6:2005-09-14 16:43:17(date)>
[2005-09-14 16:43:39 EST] <WorkerThread11> === Rollback
Internal Transaction
[2005-09-14 16:43:39 EST] <WorkerThread11> Server exception:
sqlStringForKeyValueQualifier: attempt to generate SQL for
com.webobjects.eocontrol.EOKeyValueQualifier (NeededByEOF0 = 5)
failed because attribute identified by key 'NeededByEOF0' was
not reachable from from entity 'Asset'
[2005-09-14 16:43:39 EST] <WorkerThread11>
com.webobjects.eoaccess.EOGeneralAdaptorException:
sqlStringForKeyValueQualifier: attempt to generate SQL for
com.webobjects.eocontrol.EOKeyValueQualifier (NeededByEOF0 = 5)
failed because attribute identified by key 'NeededByEOF0' was
not reachable from from entity 'Asset'
at
com.webobjects.eoaccess.EODatabaseContext._exceptionWithDatabaseCon
textInformationAdded(EODatabaseContext.java:4686)
at com.webobjects.eoaccess.EODatabaseContext.performChanges
(EODatabaseContext.java:6394)
at
com.webobjects.eocontrol.EOObjectStoreCoordinator.saveChangesInEdit
ingContext(EOObjectStoreCoordinator.java:415)
at com.webobjects.eocontrol.EOEditingContext.saveChanges
(EOEditingContext.java:3187)
at com.webobjects.eodistribution.EODistributionContext
$_RemoteMethodReceiver.clientSideRequestSave
(EODistributionContext.java:1071)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Now the NeededByEOF0 = 5 refers to the Asset's primary_key (in
fact I manually changed it from 3 to 5 in the database and sure
enough the value changed here). I think the relationships are
right because problems there usually result in an 'unable to
generate SQL' on an _EOFinv.<realtionship path> key, but I have
a problem on NeededByEOF0, so it looks like Asset is having a
problem referencing itself.
I know that NeededByEOF0 is an internal thing in EOF, but why is
it using it here, instead of PRIMARY_KEY?
I have been through the model with a fine-tooth comb, and
everything looks alright, but what could I be missing.
I even removed the 'abstract' from Test_result java class (like
last weeks Skills_test problem), but that did not work.
I have seen some problems mentioned in past posts that there
could be a bug in EOF with relationships that reference an
abstract type with subclasses. Is this still the case and hence
my problem?
Any insights most welcome
Thanks
Ian Joyner
Sportstec
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden