Re: Duplicate record
Re: Duplicate record
- Subject: Re: Duplicate record
- From: "A. Uchida" <email@hidden>
- Date: Wed, 21 Jul 2004 21:12:47 +0100
Hi Hunter,
Thanks very much for your comment.
Let me try again to explain the problem...
There are 2 components (2 pages)
DetailViewPage (showing details of a product record)
protected Product aProduct = new Product();
(Product is an entity, properties are passed from a previous
page)
public productInputPage actEditProduct() {
productInputPage nextPage =
(productInputPage)pageWithName("productInputPage");
EOEditingContext ec = session().defaultEditingContext();
ec.insertObject((Product)aNewProduct);
setANewProduct(aProduct);
nextPage.setAProduct(aNewProduct);
return nextPage;
}
public void setANewProduct(Product newProduct) {
aNewProduct = newProduct;
}
productInputPage (text boxes for new/editing record)
protected Product aProduct; (new instance to display/Edit binded to
text boxes)
Method
public productListPage actSaveNewProduct() {
productListPage nextPage =
(productListPage)pageWithName("productListPage");
aProduct.setCreatedDate(new NSTimestamp());
session().defaultEditingContext().saveChanges();
return nextPage;
}
public void setAProduct(Product newAProduct) {
aProduct = newAProduct;
}
aProduct in the detailViewPage holding a details which is going to be
edited.
I want to insert a new object and set details of aProduct to the new
object and then
pass the new object to aProduct in the next productInputPage.
Once the details passed to aProduct in the productInputPage, I will
modify them and
save them as a new record.
But the above codes gets the error of "CreatedDate not allowed to be
null"
I hope everything is now clear.
Actually I am not sure this way is the one I need to do.
(insert new object -> set detail to new object -> pass to next page and
save)
Thanks very much for your help in advance.
A. Uchida
On 21 Jul 2004, at 17:35, Hunter Hillegas wrote:
Posting full stack traces would be helpful.
Looking at your code, I don't see where you are setting createdDate...
What does setANewProduct() do? It is a method in the component? Or is
it a method on the next component?
To pass an object between components, define a setter on the second
component and simply call it. It looks like you are doing that with
your last line of code...
At this point I'm not sure what you are having a problem with... From
what you have posted so far, it still looks as if you are not setting
the second (duplicate) products setters anywhere... At least you
didn't post that code...
If a field that is set not-null is throwing a NullPointerException or
the equivalent, it is not being set somewhere.
On Jul 20, 2004, at 6:02 PM, A. Uchida wrote:
Thanks for your comment.
Here is my code. Actually I am now getting the other error, "not
allowed to be null"
for the not-null field (createdDate). I supposed this is caused by
unbinding of inserted
object and akey which contains old data when I throw them to nextPage.
Product aNewProduct = new Product();
EOEditingContext ec = session().defaultEditingContext();
ec.insertObject((Product)aNewProduct);
setANewProduct(aProduct);
nextPage.setAProduct(aNewProduct);
aProducts is a key of Entity Product and this name is also used in
nextPage.
I tried to set ec.insertedObjects()
[nextPage.setAProduct(ec.insertedObjects())] but
it gets "not possible to convert the class" error when compiling.
How can I throw the inserted object to nextPage with aProduct data?
I don't think you can just set the objects equal like that. You
would want to call all of the getters and setters for the
properties, i.e.:
newEO.setMyProperty(oldEO.myProperty());
I understood this as I have to set only the necessary data to
aNewProduct instance
one by one by means of class method.
But I couldn't throw the inserted object to nextPage properly yet....
The above my code set the data of aProduct to aProduct in nextPage,
but not allowed
to be null error occurred. This means, I supposed, that
setCreatedDate sets a date
to aProduct.createdDate, not insterted objects' createdDate. So I
supposed that
the inserted object are not binded to aProduct in the nextPage.
Any advice would be great.
Thanks in advance.
On 21 Jul 2004, at 00:33, Hunter Hillegas wrote:
You are doing something like this?
MyEO newEO = new MyEO();
editingContext.insertObject(newEO);
newEO = oldEO;
editingContext.saveChanges()?
I don't think you can just set the objects equal like that. You
would want to call all of the getters and setters for the
properties, i.e.:
newEO.setMyProperty(oldEO.myProperty());
Does that help?
On Jul 20, 2004, at 3:57 PM, A. Uchida wrote:
No, The diamond was checked off and the primary key field is
invisible from the application.
Should I manually nullify the primary key in the application with
the diamond checked in the EOModel?
I didn't try it yet, because it doesn't look proper way for me.
I found my email was a bit blurred.
When modifying a record, I want to make the duplication with new
primary key.
So I inserted a new object and set the modifying record to the new
object to allow to be edited
and then do saveChanges(). The primary key of the original records
are also set to
the new object but I was expecting the primary key will be set as
new automatically when saveChanges().
Or there may be another method to do this? (Sorry I don't know the
way to find a proper method in the API
documents)
On 20 Jul 2004, at 23:41, Hunter Hillegas wrote:
Is your primary key a class property (is the little diamond
checked in EOModeler)?
This can cause EOF to try to update a primary key, which causes
exception fever.
On Jul 20, 2004, at 3:03 PM, A. Uchida wrote:
Hi there,
WO 5.2
Mac OS X10.3.4
Postgresql7.3.4 (pg73jdbc.jar)
When modifying an existing record in a table I want to keep the
existing record as it is,
because it might be used (relationed) to the other records in the
other table.
What I've tried was :
Show details of a record which is going to be modified
Insert new object into the table
Copy the details of record to the inserted object
and saveChanges()
But it gets primary key duplication error.
And I tried search on web/mailing list but I couldn't find any
clue.
I even doesn't know what would be the keyword for search this
issue.
Any help would be very much appreciated.
A. Uchida
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.