Hi Roger,

I skimmed your post.

You cannot local instance an unsaved object. You just cannot do it. Don’t try 
anything clever… the EO is tied to a unit of work (editing context) and without 
ever being saved it simply is not possible to local instance it.

You may have to use the “memento” pattern for your particular case. Make a 
simple java object, nothing about DB persistence… and then make it an EO only 
after it has passed muster.
AARON ROSENZWEIG / Chat 'n Bike
e:  [email protected]  t:  (301) 956-2319             
        

On Jul 16, 2015, at 1:04 PM, Roger Perryman <[email protected]> wrote:

> Hi All!
> 
> I am having an issue with local instancing an EO and I would like some help 
> understanding the problem. I found an old thread started by Kieran Kelleher 
> where he was having similar issues. Mike Schrag had mentioned that EOF 
> couldn't tell if a new object localInstanced from another EC had later been 
> saved in the other EC which could result in collisions so it erred on the 
> side of caution. So I am probably using the method inappropriately. Hopefully 
> someone will point out the problem and offer the correct way.
> 
> I've noticed that when I localInstance a new EO (not yet saved to the 
> database) both the WebObjects and WOnder versions return null for the EO. It 
> seems odd for the method to return null if it is a new method. I wrote a 
> customized version that detects if it is a new EO and just returns the 
> original EO. I've been using it for quite some time now and it at least 
> _seemed_ to work better. My use cases must have avoided conflicts.
> 
> However, I've recently noticed problems. They may have been there before. I 
> did recently update my computer (OSX 10.10.3) and dev environment to the 
> latest WOnder (6.1.4-SNAPSHOT), Java 8 (1.8.0_45), Eclipse (4.4.2) with 
> matching WOLips. 
> 
> I'm creating a new EC because many of the objects in the original EC are 
> disposable and are not intended to be written to the DB, even if they happen 
> to change. The problem is because of passing the original EO to the new EC 
> instead of NULL that would normally be returned but the relationships cannot 
> be NULL. I wrote a clone method for some of the objects for testing but it 
> got very complex very fast because of deeper objects in the relationship. As 
> you can see from my debugging output, all required fields (*'s) are set and 
> relationships are set. 
> 
> This group is the objects in the old (original) EC and the original Invoice 
> that has not been saved yet but it has had an oid assigned. It also has a 
> to-many relationship to new ProductItem objects. 
> 
> OLD EC
>       EditingContext: ERXEC@2d334040
>       Registered [375]:       List omitted
>       Inserted   [  5]:       [Invoice PK: 250], [ProductItem PK: 74], 
> [ProductItemPayment PK: 61], 
>                               [ShoppingCart PK: 44], [ShoppingCartProduct PK: 
> 44]
>       Updated    [  3]:       <Account pk:167>, <Practice pk:1>, <User pk:2>
>       Deleted    [  0]:       EMPTY
> 
> OLD Invoice: 
>       Invoice(5bdf1c53) :
>               globalID                            = <Invoice PK: 250> { 
> pending } 
>               editingContext                      = ERXEC@2d334040            
> Added to EC 
> 
>       Attributes
>               approvedDeposit                     = NULL
>               dateRecordCreated                   = Wednesday July 15, 2015 @ 
> 03:19 PM *
>               dateRecordModified                  = Wednesday July 15, 2015 @ 
> 03:19 PM *
>               invoiceDate                         = Wednesday July 15, 2015 @ 
> 03:19 PM *
>               invoiceDiscount                     = NULL
>               invoiceNumber                       = IJD20150715151938381 *
>               isActive                            = true *
>               taxRate                             = 0.07 *
>               totalFees                           = 0.0 *
>               totalNonTaxable                     = 0.0 *
>               totalTaxable                        = 0.0 *
>               version                             = 1 *
> 
>       To-One Relationships
>               toAccount                           = <Account PK: 167> *
>               toCheckListPostOp                   = NULL
>               toCheckListPreOp                    = NULL
>               toCheckListSurgery                  = NULL
>               toCoordinator                       = <User PK: 2> ( Jane Doe ) 
>  *
>               toInvoiceStatus                     = <InvoiceStatus PK: 1> ( 
> Open )  *
>               toInvoiceType                       = <InvoiceType PK: 2> ( 
> Invoice )  *
>               toPractice                          = <Practice PK: 1> ( 
> DEFAULT_PRACTICE )  *
>               toSurgeryRequest                    = NULL
> 
>       To-Many Relationships
> 
>               toProductItems          [ 1 ]
>                       1) eoObj = <ProductItem PK: 74> { pending } 
> 
>               toRequestDetails
>                       No Records
> 
>               toServiceItems
>                       No Records
> 
> 
> This group is the objects in the new EC and the cloned Invoice that has not 
> been saved yet but it has had an oid assigned. It also has a to-many 
> relationship to new ProductItem objects. Note the oid has increased and 
> unique attributes have been adjusted. When I try to save, it fails because 
> the objects associated with ProductItems have a relationship in a different 
> EC (and retain their original oids).
> 
> NEW Invoice: 
>       Invoice(6371d408) :
>               globalID                            = <Invoice PK: 251> { 
> pending } 
>               editingContext                      = ERXEC@1c741963            
> Added to EC, Updated in EC 
> 
>       Attributes
>               approvedDeposit                     = NULL
>               dateRecordCreated                   = Wednesday July 15, 2015 @ 
> 03:30 PM *
>               dateRecordModified                  = Wednesday July 15, 2015 @ 
> 03:30 PM *
>               invoiceDate                         = Wednesday July 15, 2015 @ 
> 03:19 PM *
>               invoiceDiscount                     = NULL
>               invoiceNumber                       = IJD20150715151938952 *
>               isActive                            = true *
>               taxRate                             = 0.07 *
>               totalFees                           = 0.0 *
>               totalNonTaxable                     = 0.0 *
>               totalTaxable                        = 0.0 *
>               version                             = 1 *
> 
>       To-One Relationships
>               toAccount                           = <Account PK: 167> *
>               toCheckListPostOp                   = NULL
>               toCheckListPreOp                    = NULL
>               toCheckListSurgery                  = NULL
>               toCoordinator                       = <User PK: 2> ( Jane Doe ) 
>  *
>               toInvoiceStatus                     = <InvoiceStatus PK: 1> ( 
> Open )  *
>               toInvoiceType                       = <InvoiceType PK: 2> ( 
> Invoice )  *
>               toPractice                          = <Practice PK: 1> ( 
> DEFAULT_PRACTICE )  *
>               toSurgeryRequest                    = NULL
> 
>       To-Many Relationships
> 
>               toProductItems          [ 1 ]
>                       1) eoObj = <ProductItem PK: 74> { pending } 
> 
>               toRequestDetails
>                       No Records
> 
>               toServiceItems
>                       No Records
> 
> NEW ProductItems: 
> (
>       ProductItem(1695d9bc) :
>               globalID                            = <ProductItem PK: 74> { 
> pending } 
>               editingContext                      = ERXEC@2d334040            
> Added to EC, Updated in EC 
> 
>       Attributes
>               dateRecordCreated                   = Wednesday July 15, 2015 @ 
> 03:15 PM *
>               dateRecordModified                  = Wednesday July 15, 2015 @ 
> 03:15 PM *
>               discountAmount                      = 0.0 *
>               isActive                            = true *
>               unitAmount                          = 100.0 *
>               unitQuantity                        = 1 *
>               version                             = 1 *
> 
>       To-One Relationships
>               toAuthorizedBy                      = NULL
>               toInvoice                           = <Invoice PK: 250> { 
> pending }
>               toProduct                           = <Product PK: 3> ( 
> Abdominoplasty Garment )  *
> 
>       To-Many Relationships
> 
>               toGiftCards
>                       No Records
> 
>               toPayments
>                       No Records
> 
>               toProductItemPayments           [ 1 ]
>                       1) eoObj = <ProductItemPayment PK: 61> { pending } 
> 
>               toShoppingCartProducts          [ 1 ]
>                       1) eoObj = <ShoppingCartProduct PK: 44> { pending } 
> )
> 
> NEW EC
>       EditingContext: ERXEC@1c741963
>               Registered [179]:       List omitted
>               Inserted   [  1]:       [Invoice PK: 251]
>               Updated    [  3]:       <Account pk:167>, <Practice pk:1>, 
> <User pk:2>
>               Deleted    [  0]:       EMPTY
> 
> 
> Is there a correct way to "localInstance" an unsaved EO? Or do I need to 
> restructure the code and perhaps use nested ECs?
> 
> Thanks,
> 
> Roger
> 
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      ([email protected])
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/aaron%40chatnbike.com
> 
> This email sent to [email protected]

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to