• 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: Unexpected awakeFromInsertion() behaviour
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unexpected awakeFromInsertion() behaviour


  • Subject: Re: Unexpected awakeFromInsertion() behaviour
  • From: Peter Vandoros <email@hidden>
  • Date: Thu, 10 Jan 2008 09:49:51 +1100

Hi Chuck,

Chuck Hill wrote:
Hi Peter,

On Jan 8, 2008, at 9:23 PM, Peter Vandoros wrote:

Hi List,

I came across an interesting behaviour today with awakeFromInsertion() that i did not expect and I hope someone could shed some light.

What happens is that awakeFromInsertion() is not only called when the EO is "created" but also when reverting the editing context after having deleted an EO (which hasn't yet been saved). That is, if you delete an EO and revert() instead of saveChanges(), that EO's awakeFromInsertion() method is called again.

The documentation states:
"Overridden by subclasses to perform additional initialization on the receiver upon its being inserted into ec. This is commonly used to assign default values or record the time of insertion. ...."

I originally took this to mean that it is only called when the EO is _created_. Technically speaking, the documentation states that it is called when the EO is _inserted_ into the editing context which does not necessarily mean when the EO is _created_.

Does this mean that I need to go through all my EO's that use this method for some initialisation and take this scenario into account or is this a bug with WO?
I am using WO 5.2.4.

Is this what you are talking about?

com.webobjects.eocontrol.EOEditingContext ec = newEditingContext();
ec.lock();
Order o = new Order();
ec.insertObject(o);
ec.deleteObject(o);
ec.revert();
ec.unlock();

I log a stack trace from Order.awakeFromInsertion.  I do not get a call to awakeFromInsertion when the ec is reverted in WO 5.3.3.

Log out a stack trace from awakeFromInsertion and see what it says for the second call:

    public void awakeFromInsertion(EOEditingContext ec)
    {
        NSLog.out.appendln(new RuntimeException("backtrace"));
        super.awakeFromInsertion(ec);
        . . .

I'd be interested to see it.
That is not exactly what i am talking about.

The code below demonstrates what i am talking about.

EOEditingContext ec = new EOEditingContext();
ec.lock();
try {
    Order order = (
Order) EOUtilities.createAndInsertInstance( ec, "Order" );

    // set order properties so it can be saved successfully

    ec.saveChanges();

    ec.deleteObject( order);

    NSLog.out.appendln("should see awakeFromInsertion call now...");
    ec.revert();
    NSLog.out.appendln("did you see the awakeFromInsertion call?");
}
catch (Exception e) {
    System.err.println("Error with test");
    e.printStackTrace();
}
finally {
    ec.unlock();
}


The stack trace (the interesting part) that i get when this happens is:

java.lang.RuntimeException: backtrace
    at com.etechgroup.test.eo.Order.awakeFromInsertion(
Order.java:44)
    at com.webobjects.eocontrol.EOEditingContext.insertObjectWithGlobalID(EOEditingContext.java:2851)
    at com.webobjects.eocontrol.EOEditingContext.insertObject(EOEditingContext.java:2871)
    at com.webobjects.eocontrol.EOEditingContext.revert(EOEditingContext.java:4570)


It looks as though the editing context re-inserts a deleted EO if that EO is not newly created and you revert.

Thanks
--
Peter Vandoros
Software Engineer
Etech Group Pty Ltd
Level 3/21 Victoria St
Melbourne VIC 3000
Australia

Ph: +61 3 9639 9677
Fax: +61 3 9639 9577
----------------------------------
IMPORTANT: This e-mail message and any attachments are confidential and may be privileged. If received in error, please reply to this message and destroy all copies and any attachments. You should check this message and any attachments for viruses or defects. Our liability is limited to resupplying any affected message or attachments. For more information about Etech Group, please visit us at http://www.etechgroup.com.au.
 _______________________________________________
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: Unexpected awakeFromInsertion() behaviour
      • From: Chuck Hill <email@hidden>
References: 
 >Unexpected awakeFromInsertion() behaviour (From: Peter Vandoros <email@hidden>)
 >Re: Unexpected awakeFromInsertion() behaviour (From: Chuck Hill <email@hidden>)

  • Prev by Date: Re: Repeating a component output in the same page
  • Next by Date: Re: Repeating a component output in the same page
  • Previous by thread: Re: Unexpected awakeFromInsertion() behaviour
  • Next by thread: Re: Unexpected awakeFromInsertion() behaviour
  • Index(es):
    • Date
    • Thread