Re: Global ID mixup when adding to "many to many" relationship
Re: Global ID mixup when adding to "many to many" relationship
- Subject: Re: Global ID mixup when adding to "many to many" relationship
- From: Chuck Hill <email@hidden>
- Date: Tue, 4 Jan 2011 13:26:29 -0800
On Dec 29, 2010, at 10:21 AM, Jeff Schmitz wrote:
> Hello,
> I'm not sure how the following can happen, but I seem to have figured out a way to make it so. My code creates a new EO (user) and then adds an existing EO (this) to a "many to many" relationship of the new EO as shown with added logged messages:
>
> User user = User.createUser(this.editingContext(), password, eMail, first, forumName, last, lastYearUser, userName, real, thisYear, useFBAccount, useFBLogin);
> this.editingContext().saveChanges();
> EOGlobalID poolID = this.editingContext().globalIDForObject(this);
> EOGlobalID userID = this.editingContext().globalIDForObject(user);
> System.out.println("Adding user " + user.name() + " with ID " + userID + " to Pool " + this.name() + " with id " + poolID);
> user.addToPoolsRelationship(this);
> this.editingContext().saveChanges();
>
> Note that the first saveChanges after creation of the new EO works fine. But after the second saveChanges I get the below constraint error. The strange part is that when printing out the ID's of the EO's, it looks like it should be using a User EO with an ID of 1000009. However, the integrity error makes it look like it tried to add "this" to a user with ID 1000007.
>
>
> Dec 29 11:53:24 netBrackets[9999] (Pool.java:407) INFO com.netbracketsfw.model.Pool - Adding user Wilma with ID _EOIntegralKeyGlobalID[User (java.lang.Integer)1000009] to Pool VVV0 with id _EOIntegralKeyGlobalID[Pool (java.lang.Integer)1000005]
>
> Dec 29 11:53:24 netBrackets[9999] (ERXDatabaseContextDelegate.java:175) INFO er.transaction.adaptor.Exceptions - Database Exception occured: com.webobjects.eoaccess.EOGeneralAdaptorException: EvaluateExpression failed: <com.webobjects.jdbcadaptor._FrontBasePlugIn$FrontbaseExpression: "INSERT INTO "PoolUser"("userId", "poolId") VALUES (1000007, 1000005)" withBindings: >:
> Next exception:SQL State:23 subclass = 00 -- error code: 358 -- msg: Exception condition 358. Integrity constraint violation (PRIMARY KEY, PoolUser.PRIMARY_KEY_PoolUser_userId_poolId(userId=1000007,poolId=1000005)).
> Next exception:SQL State:40 subclass = 00 -- error code: 363 -- msg: Exception condition 363. Transaction rollback.
It looks like it is trying to re-insert an existing row. This usually means that somewhere you have violated one of the EOF commandments and the EC state got confused. Is this.editingContext() locked?
Chuck
>
> Finally, I'm using Wonder, with the InverseRelationshipUpdater turned on, i.e. addToPools gets called.
>
> public void addToPoolsRelationship(com.netbracketsfw.model.Pool object) {
> if (_User.LOG.isDebugEnabled()) {
> _User.LOG.debug("adding " + object + " to pools relationship");
> }
> if (er.extensions.eof.ERXGenericRecord.InverseRelationshipUpdater.updateInverseRelationships()) {
> addToPools(object);
> }
> else {
> addObjectToBothSidesOfRelationshipWithKey(object, "pools");
> }
> }
>
> any ideas what's going on?
>
> Thanks!
> Jeff
>
> _______________________________________________
> 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
--
Chuck Hill Senior Consultant / VP Development
Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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