• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Saving entities problem [SOLVED]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Saving entities problem [SOLVED]


  • Subject: Re: Saving entities problem [SOLVED]
  • From: Jevon Hills <email@hidden>
  • Date: Tue, 29 Jul 2003 09:56:51 -0600

Thanx for your reply Art. As you may know this is not my first attempt at trying to model the 3 way. With each attempt I get more into the WO way and away from SQL.

I have just played around with eomodeler a little and would like to try and explain what is happening as I understand it. Then if any of you wish to 'correct' me, or 'nudge' me closer to the path (if I'm not on it) that would be most appreciated. I have attempted to create these models in ASCII ART, but this does not always work for me so I have put the art at the bottom of my message so as not to mess things up too badly.

WARNING: RATHER A LENGTHY MESSAGE FOLLOWS


THE TWO-WAY MODEL (MANY TO MANY) (See DIAGRAM 1)

I decided to create a new set of tables to work with: pubUser and pubApplication.
I then created a new model using these tables. Using EOModeler I joined the entities. (Join in Many to Many).


What it created was the Intermeadiate table (pubUserPubApplication) for me with the to PK's as FK's and 2 relationships to the original entities, but none of these would be visible to a Java Class (Class Properties). In the original entities it also created two relationships. One was a To-Many relationship to the Join entity (not a class property) and the other a Flattened relationship to through the join to the other Original Entity. (See DIAGRAM 1)

Then (as I understand it) in my code if I have an Application obj (anApp) and wish to add a User obj (aUser) to it i write the following: anApp.addObjectToBothSidesOfRelationshipWithKey(aUser, "pubUser");
This will essentially maintain the join for me.


Assuming that what I understand is correct I will now attempt to transfer this to the 3-way model (Here's Hopin')



THE THREE-WAY MODEL (MANY TO MANY TO MANY) (See DIAGRAM 2)

Using 4 entities: pubUser, pubApplication, pubPermission, and pubUserAppPerms.

Each of the primary entities there will be three relationships, two of them will be Flattened and class Properties and one of them will be a To-Many relationship that is not a class property. For example the pubUser entity now has one attribute 'pubUserID' and 3 relationships: 'pubApps'(flattened relationship to pubApplication),'pubPerms'(flattened relationship to pubPermission), and 'pUserAppPerms' a To-Many relationship to the join table.

The join table will also have three attributes and three relationships, but none of them will be class properties. Table pubUserAppPerms will have pubUserID, pubPermissionID, and pubApplicationID as attributes and pUser, pApp, pPerm as relationships to each entity.

In code then I believe I can do the following:
myClass
{
	pubUser aUser;
	pubApplication  anApp;
	pubPermission aPerm;
	EOEditingContext editingContext;

aUser.addObjectToBothSidesOfRelationshipWithKey(anApp, "pubApplication");
aUser. addObjectToBothSidesOfRelationshipWithKey(aPerm, "pubPermission")


	editingContext.saveChanges()
}

CONCLUSION (and it's about time. ed.)
I think that I understand a little more about EOModeler and its uses. I hope that my ramblings were not too much and that they might help others. Once again if I not directly on target, or Completly off the Mark I hope that the members of the list will help correct my inaccuracies.


ttfn

Jevon K. Hills
Developer - Zymeta Media Promotion Systems


ASCII Art Follows

KEY
PK - PrimaryKey
FK - ForeignKey
V  - Class Property (visable)

DIAGRAM 1
----------------- -------------------- ----------------
|pubUser | |pubUserApplication| |pubApplication|
|---------------| |------------------| ----------------
|pubUserID PK |==============|pubUserID FK |===============|pubAppID PK |
----------------- |pubAppID FK | ----------------
|pubApps V| |------------------| |pubUsers V|
|pUserApps | |pUser | |pUserApps |
----------------- |pApp | ----------------
--------------------







DIAGRAM 2

----------------- -------------------- ----------------
|pubUser | |pubUserAppPerm | |pubApplication|
|---------------| |------------------| ----------------
|pubUserID PK |==============|pubUserID FK |===============|pubAppID PK |
----------------- |pubAppID FK | ----------------
|pubApps V| |pubPermID FK | |pubUsers V|
|pubPerms V| |------------------| |pubPerms V|
|pUserAppPerms | |pUser | |pUserAppPerms |
----------------- |pApp | ----------------
|pPerm |
--------------------
=
=
=
=
=
-----------------------
|pubPermission |
-----------------------
|pubPermissionID PK |
-----------------------
|pubApps V|
|pubUsers V|
|pUserAppPerms |
-----------------------




On Monday, July 28, 2003, at 04:02  PM, Art Isbell wrote:

On Monday, July 28, 2003, at 06:21  AM, Jevon Hills wrote:

	And set it's values
		at.setPermission(canUse);
		at.setApplications(mlp);
		at.setUsers(aUsers);
	And then save the changes
again(this.session().defaultEditingContext().saveChanges();)
**This Does not work.

On Monday, July 28, 2003, at 07:31 AM, Jevon Hills wrote:

The problem I had was my 3 FK columns would not accept nulls in either the DB or the EOModel. When I was generating the object these of course were null vaulus until the sql is generated. By allowing nulls these worked just fine.

These primary key values should not be null, so I suspect by allowing these to be null, you may be covering up another problem that will come back to haunt you later (they always do :-)


The problem might be a modeling problem. EOModeler supports a 2-entity many-to-many relationship, but not a 3-entity many-to-many relationship as in your case. So you'll need to build this manually. This can be very tricky to do correctly. What I've done in similar situations is let EOModeler build a 2-entity many-to-many relationship and then copy exactly what EOModeler did but with 3 entities. This requires examining each relationship EOModeler creates, setting the relationship delete rules, propagate primary key property, etc., flattening proper relationships, ensuring that both the flattened and underlying relationships aren't both class properties, etc.

The other problem might be your code. You shouldn't use relationship setter methods directly; instead use addObjectToBothSidesOfRelationshipWithKey(). This method will use setter methods for both sides of each relationship; i.e. the relationship and its inverse, if any. Failure to set both sides of each relationship can result in the object graph being incomplete which can lead to SQL that doesn't set database values correctly.

Aloha,
Art
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Saving entities problem [SOLVED] (From: Art Isbell <email@hidden>)

  • Prev by Date: Re: Correct "Logout" Action
  • Next by Date: Re: Saving entities problem [SOLVED]
  • Previous by thread: Re: Saving entities problem [SOLVED]
  • Next by thread: Re: Saving entities problem [SOLVED]
  • Index(es):
    • Date
    • Thread