• 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: Louis Demers <email@hidden>
  • Date: Thu, 12 Jul 2012 17:58:01 -0400

On 2012-07-12, at 2:46 PM, Hugo Cambero wrote:

> Hi Everybody
>
> My name is Hugo, I'm from Mexico. I have been developing using WebObjects and Wonder Frameworks, I'm newbie in this topic.
>
> Well, I have a problem, I hope you can help me. I'm developing a test application, I want to learn about EOF.
>
> I have 2 entities, that I created using EOModel. The first entity is: User, the second is Role. The relationship between the entities is: One user
> can have many Roles.
>
> Well, I tried to insert a row using the next code:
>
>                     EOEditingContext ec = ERXEC.newEditingContext();
>                     Role userRole = Role.fetchRole( ec, Role.NAME.eq("user") ); //Get the correct Role to the new user
>
>                     User newUser = new User();
>                     newUser.setName( name.toLowerCase() );
>                     newUser.setPaternalName( paternalName.toLowerCase()  );
>                     newUser.setMaternalName( maternalName.toLowerCase() );
>                     newUser.setBirthday( new NSTimestamp() );
>                     newUser.setUsername( username );
>                     newUser.setPassword( password );
>
>                     newUser.setRole( userRole );                   //Set the role to the user
>
>                     ec.insertObject( newUser );                    //Insert object to the EOEditingContext

one of the WO commandments:

always insert your EO immediately after creating it. i.e. after new User() and before setting any attributes.

alternatively you can use

User newUser = (User)EOUtilities.createAndInsertInstance(ec, User.ENTITY_NAME) ;



>                     ec.saveChanges();                                //Commit to the DataBase
>
> But, the server has the next error:
>
> java.lang.RuntimeException: You crossed editing context boundaries attempting to set the 'role' relationship of <your.app.model.User pk:"null"> (which is not in an editing context) to <your.app.model.Role pk:"2"> (in EC er.extensions.eof.ERXEC@762a5241).
>
> I understand that the primary key of the user is null, because it's a new user and I want to insert it to the data base.
>
> What is the correct way to insert row, when it have a relationship between the entities?
>
> Thanks for you time
>
>
>
>
>
> _______________________________________________
> 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

Louis Demers eng.
www.obzerv.com


 _______________________________________________
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: David Holt <email@hidden>
    • Re: Problem EOEditingContext
      • From: Maik Musall <email@hidden>
References: 
 >Problem EOEditingContext (From: Hugo Cambero <email@hidden>)

  • Prev by Date: Re: Adaptor problem with SSL on Ubuntu
  • Next by Date: Re: Problem EOEditingContext
  • Previous by thread: Re: Problem EOEditingContext
  • Next by thread: Re: Problem EOEditingContext
  • Index(es):
    • Date
    • Thread