Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Instantiating Enterprise Objects

There are at least a few ways to create enterprise objects programmatically. The approach you use largely depends on the configuration of the entity from which you want to create the object.

In EOModeler, if the entity’s class is assigned to EOGenericRecord, you must first retrieve the entity’s class description before instantiating an enterprise object. An entity’s class description holds meta-information about an entity that describes an entity’s various characteristics, such as its attributes and relationships. Once you have an entity’s class description, you can instantiate an enterprise object of that class.

For example, consider the Listing entity described in “Reference Entity.” You can use this code to instantiate an enterprise object of type Listing:

EOClassDescription listingCD =           EOClassDescription.classDescriptionForEntityName("Listing");
EOEnterpriseObject listing =
         listingCD.createInstanceWithEditingContext(null, null);
editingContext.insertObject(listing);

Note that immediately after the enterprise object is created, it is inserted into an editing context. As a cardinal rule, all enterprise objects reside in an editing context. This is necessary in order for enterprise objects to send and receive the notifications necessary for change tracking and other mechanisms within Enterprise Objects. So, for every enterprise object you create, you must immediately insert it into an editing context.

You can simplify the above code example by supplying an editing context object as the first argument to the createInstanceWithEditingContext invocation.

If an entity’s class is assigned to a custom subclass of EOGenericRecord (so that the Listing entity’s class name assignment in EOModeler is “Listing” or “com.myapp.Listing”), you can also create an enterprise object with this code by using the subclasses’s constructor:

Listing image = new Listing();
editingContext.insertObject(image);

You can also use the method in the EOUtilities class called createAndInsertInstance to instantiate an enterprise object:

EOUtilities.createdAndInsertInstance(editingContext(), "Listing");


< Previous PageNext Page > Hide TOC


Last updated: 2007-07-11




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice