• 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: Foreign keys and database operation ordering
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Foreign keys and database operation ordering


  • Subject: Re: Foreign keys and database operation ordering
  • From: Cedarstone <email@hidden>
  • Date: Thu, 12 Feb 2009 11:01:08 +0000

Thanks Chuck

Once again Wonder has a solution. I wish you'd write another book and incorporate all the Wolips and Wonder goodies into it!

Giles




On Feb 11, 2009, at 9:44 AM, Cedarstone wrote:

Hi

I am using MySQL with WO on a new application so have control over how things are implemented. I am unsure what is the best way to work with foreign key constraints for actions such as database inserts and deletes to make sure that database actions are done in the correct order to avoid foreign key constraint errors.

I know this is a fairly common EOF problem but am interested in WO gurus' views. From what I can tell there are three ways to get round this ordering problem, unfortunately the first is not an option for me using MySQL:

1) Use "DEFERRABLE INITIALLY DEFERRED" option for your foreign keys.
Not an option for MySQL as it is not supported.

2) Do not use foreign key constraints in the MySQL tables and instead rely on the EOModel to implement the equivalent constraints.

3) Implement a EODatabaseContext.Delegate object with the databaseContextWillPerformAdaptorOperations method to manually control the ordering of operations.

Use Wonder. Set main() in Application up like this:

public static void main(String argv[])
{
ERXDatabaseContextMulticastingDelegate.addDefaultDelegate(new ERXEntityDependencyOrderingDelegate());
// Ensure that we get proper error pages when an exception happens in a direct action.
// This must go here and not in the constructor or it won't work.
System.setProperty("WODisplayExceptionPages", "true");
WOApplication.main(argv, Application.class);
}


Note that this does not handle the case where EOs have relationships back to themselves. It only handles ensuring that the tables are updated in an order that satisfies the FK constraints.


Given that option 1 is not available for me what is the preferred way to handle this ordering issue from 2 and 3?

Any advise welcome!



Chuck

--
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








_______________________________________________ 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
  • Follow-Ups:
    • Re: Foreign keys and database operation ordering
      • From: David Avendasora <email@hidden>
References: 
 >Foreign keys and database operation ordering (From: Cedarstone <email@hidden>)
 >Re: Foreign keys and database operation ordering (From: Chuck Hill <email@hidden>)

  • Prev by Date: Drupal profile table, how to handle this in webobjects?
  • Next by Date: Re: Drupal profile table, how to handle this in webobjects?
  • Previous by thread: Re: Foreign keys and database operation ordering
  • Next by thread: Re: Foreign keys and database operation ordering
  • Index(es):
    • Date
    • Thread