• 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: Problem EOEditingContext
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem EOEditingContext


  • Subject: Re: Problem EOEditingContext
  • From: Maik Musall <email@hidden>
  • Date: Fri, 13 Jul 2012 11:23:04 +0200

Am 13.07.2012 um 01:20 schrieb Ramsey Gurley:

>
> On Jul 12, 2012, at 3:26 PM, Maik Musall wrote:
>
>>
>> Am 12.07.2012 um 23:58 schrieb Louis Demers:
>>> User newUser = (User)EOUtilities.createAndInsertInstance(ec, User.ENTITY_NAME) ;
>>
>> Much too wordy for my taste, and needs a cast on top of it. Just add a second constructor in your template which does ec.insertObject(this), so that you can simply use
>>
>> 	User newUser = new User( ec );
>>
>> Do not delete the parameter-less constructor though, because EOF needs that internally when restoring objects from db. But refrain from using that anywhere in your app.
>>
>> Maik
>
> I know the rule is not followed strictly in WO/Wonder, but as a general rule in java, do not let 'this' escape the constructor.
>
> http://www.javapractices.com/topic/TopicAction.do?Id=252

Indeed, you're right. Using a factory method is the better way. I just looked into what insertObject() actually does and it's really more than you would want to happen inside a constructor, although I never had a problem with this in years. Still, I'd make a factory method in the template to be called like

	User newUser = User.newInEc( ec );

Side note: javapractices.com is good, but not infallible. For example, it is badly misguided
about spaces instead of tabs... ;-)     (http://www.javapractices.com/topic/TopicAction.do?Id=244)

Maik
 _______________________________________________
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: Problem EOEditingContext
      • From: Ramsey Gurley <email@hidden>
    • Re: Problem EOEditingContext
      • From: "Cheong Hee (Gmail)" <email@hidden>
References: 
 >Problem EOEditingContext (From: Hugo Cambero <email@hidden>)
 >Re: Problem EOEditingContext (From: Louis Demers <email@hidden>)
 >Re: Problem EOEditingContext (From: Maik Musall <email@hidden>)
 >Re: Problem EOEditingContext (From: Ramsey Gurley <email@hidden>)

  • Prev by Date: Re: Anyone like to transcripti WOWODC podcasts via Mechanical Turk?
  • Next by Date: Re: Migrating from EOF to Cayenne
  • Previous by thread: Re: Problem EOEditingContext
  • Next by thread: Re: Problem EOEditingContext
  • Index(es):
    • Date
    • Thread