What is wrong with this code?
What is wrong with this code?
- Subject: What is wrong with this code?
- From: Kevin Windham <email@hidden>
- Date: Thu, 12 Apr 2007 16:07:26 -0500
I have a user class in my session class. I also have a club class. I
am trying to add a new club to my user and am using the following code.
Session session = (Session)session();
EOEditingContext ec = session.defaultEditingContext();
Club club = new Club();
ec.insertObject(club);
club.setApproved(false);
club.setClubName(clubName);
club.setWebsite(clubWebsite);
session.user.addToClubs(club);
ec.saveChanges();
The code causes an exception at the addToClubs(club) line. I am
unsure as to why this is. I have used similar code before. My guess
is that it has something to do with the eomodel and the way many to
manys work versus one to manys. The other code I've written like this
before deals with one to many relationships. In this case, the user-
clubs is a many to many. From what I've read in the docs, WO should
be able to handle the linking table automatically, but it doesn't
seem to be working that way. Did I miss something, or does this just
not work this way?
Thanks,
Kevin
Here is the exception and trace.
Error:
java.lang.ClassCastException: com.webobjects.foundation.NSArray
Reason:
com.webobjects.foundation.NSArray
Stack trace:
File Line# Method Package
NSArray.java 1167 _mutableComponentsSeparatedByString
com.webobjects.foundation
EOSQLExpression.java 1885 sqlStringForSchemaObjectName
com.webobjects.eoaccess
EOSQLExpression.java 264 _aliasForRelatedAttributeRelationshipPath
com.webobjects.eoaccess
EOSQLExpression.java 1168 joinExpression com.webobjects.eoaccess
EOSQLExpression.java 1033 prepareSelectExpressionWithAttributes
com.webobjects.eoaccess
JDBCExpression.java 273 prepareSelectExpressionWithAttributes
com.webobjects.jdbcadaptor
EOSQLExpressionFactory.java 226 selectStatementForAttributes
com.webobjects.eoaccess
JDBCChannel.java 178 selectAttributes com.webobjects.jdbcadaptor
EODatabaseChannel.java 878
_selectWithFetchSpecificationEditingContext com.webobjects.eoaccess
EODatabaseChannel.java 215 selectObjectsWithFetchSpecification
com.webobjects.eoaccess
EODatabaseContext.java 3205
_objectsWithFetchSpecificationEditingContext com.webobjects.eoaccess
EODatabaseContext.java 3346 objectsWithFetchSpecification
com.webobjects.eoaccess
EOObjectStoreCoordinator.java 539 objectsWithFetchSpecification
com.webobjects.eocontrol
EOEditingContext.java 4114 objectsWithFetchSpecification
com.webobjects.eocontrol
ERXEC.java 1075 objectsWithFetchSpecification er.extensions
EODatabaseContext.java 4260 objectsForSourceGlobalID
com.webobjects.eoaccess
EOObjectStoreCoordinator.java 682 objectsForSourceGlobalID
com.webobjects.eocontrol
EOEditingContext.java 3965 objectsForSourceGlobalID
com.webobjects.eocontrol
ERXEC.java 1036 objectsForSourceGlobalID er.extensions
EODatabaseContext.java 4427 _fireArrayFault com.webobjects.eoaccess
EOAccessArrayFaultHandler.java 70 completeInitializationOfObject
com.webobjects.eoaccess
_EOCheapCopyMutableArray.java 38 willRead com.webobjects.eocontrol
_EOCheapCopyMutableArray.java 92 count com.webobjects.eocontrol
NSArray.java 639 containsObject com.webobjects.foundation
EOCustomObject.java 907 includeObjectIntoPropertyWithKey
com.webobjects.eocontrol
User.java 212 addToClubs User
MyClubs_AddClubRequest.java 32 submitAction MyClubs_AddClubRequest
NativeMethodAccessorImpl.java NA invoke0 sun.reflect
NativeMethodAccessorImpl.java 39 invoke sun.reflect
DelegatingMethodAccessorImpl.java 25 invoke sun.reflect
Method.java 585 invoke java.lang.reflect
KeyValueCodingProtectedAccessor.java 54 methodValue
KeyValueCodingProtectedAccessor
NSKeyValueCoding.java 1160 valueInObject com.webobjects.foundation
NSKeyValueCoding.java 1268 valueForKey com.webobjects.foundation
WOComponent.java 1539 valueForKey com.webobjects.appserver
NSKeyValueCoding.java 498 valueForKey com.webobjects.foundation
NSKeyValueCodingAdditions.java 212 valueForKeyPath
com.webobjects.foundation
WOComponent.java 1600 valueForKeyPath com.webobjects.appserver
WOKeyValueAssociation.java 46 valueInComponent
com.webobjects.appserver._private
WOSubmitButton.java 70 invokeAction
com.webobjects.appserver._private
ERXPatcher.java 159 invokeAction er.extensions
WODynamicGroup.java 101 invokeChildrenAction
com.webobjects.appserver._private
WODynamicGroup.java 110 invokeAction
com.webobjects.appserver._private
ERXWOForm.java 127 invokeAction er.extensions
WODynamicGroup.java 101 invokeChildrenAction
com.webobjects.appserver._private
WODynamicGroup.java 110 invokeAction
com.webobjects.appserver._private
WOComponentContent.java 31 invokeAction
com.webobjects.appserver._private
WODynamicGroup.java 101 invokeChildrenAction
com.webobjects.appserver._private
WODynamicGroup.java 110 invokeAction
com.webobjects.appserver._private
WOComponent.java 945 invokeAction com.webobjects.appserver
WOComponentReference.java 104 invokeAction
com.webobjects.appserver._private
WODynamicGroup.java 101 invokeChildrenAction
com.webobjects.appserver._private
WODynamicGroup.java 110 invokeAction
com.webobjects.appserver._private
WOComponent.java 945 invokeAction com.webobjects.appserver
WOSession.java 1168 invokeAction com.webobjects.appserver
WOApplication.java 1375 invokeAction com.webobjects.appserver
ERXAjaxApplication.java 74 invokeAction er.extensions
ERXApplication.java 1053 invokeAction er.extensions
WOComponentRequestHandler.java 196 _dispatchWithPreparedPage
com.webobjects.appserver._private
WOComponentRequestHandler.java 287 _dispatchWithPreparedSession
com.webobjects.appserver._private
WOComponentRequestHandler.java 322 _dispatchWithPreparedApplication
com.webobjects.appserver._private
WOComponentRequestHandler.java 358 _handleRequest
com.webobjects.appserver._private
WOComponentRequestHandler.java 432 handleRequest
com.webobjects.appserver._private
WOApplication.java 1306 dispatchRequest com.webobjects.appserver
ERXApplication.java 1102 dispatchRequest er.extensions
WOWorkerThread.java 173 runOnce com.webobjects.appserver._private
WOWorkerThread.java 254 run com.webobjects.appserver._private
Thread.java 613 run java.lang
_______________________________________________
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