I think the basic problem is that when you have integer ids, FDMS does not treat “0” as the “null” id since in some cases 0 is a perfectly valid id.  When you use createItem, in some cases the client allocates the ids though more commonly they are allocated by the server and updated in the client side when the commit result returns.   For String ids, null is a signal to FDMS to expect a server side id on the commit so we create a temporary unique id in the meantime for that instance.  But with integer ids if you call createItem twice in a row before committing you’ll end up with two objects that have 0 as their id and that is considered an error.  We should have a way to indicate that “0” is a null id…. In any case, I have worked around this in the past by using an ascending sequence of negative numbers for the ids of newly created items.  You just some need some integer which gets decremented each time you call createItem and use that value as your “id” before you call createItem.  That way the ids are unique before the commit call is made as well as after. 

 

Of course that could cause problems if your server allocates negative id values as well but hopefully that is not the case.

 

Jeff

 


From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Benno Kittelmann
Sent: Tuesday, September 26, 2006 6:32 AM
To: [email protected]
Subject: [flexcoders] Add an object via DataService.createItem() to a DataGrid

 

Hello all,

I have the following (simplified) setup: An ArrayCollection is bound
to the dataProvider attribute of a DataGrid. The values of the
ArrayCollection are loaded by a DataService during startup of the
application. Additionally, there is a form which is used to create new
managed objects. Whenever the form is submitted, a new object is
created, and after a call to to createItem() it is persisted on the
server, and some seconds later displayed in the DataGrid. So far so
good.

Here's the problem though: If I try to directly add another object, I
get the error message "Item with id '0' already exists'. And the
object does not display in the DataGrid.

The object I'm trying to add/persist looks like this:

package myPackage
{
[Managed]
[RemoteClass(alias="myPackage.Item")]
public class Item {
public var id:int;
public var name:String = "";
}
}

and I'm trying to persist it like this:

var newItem:Item = new Item();
newItem.name = "foobar";
dataservice.createItem(newItem);

datagrid.dataProvider.refresh();
Alert.show(String(newItem.id));

The alert is showing me '0' as the newly generated id - which I
suppose is to be expected, since the order of method calls is not
synchronous. Anyway, when I monitor what's happening on the server, I
see that a new Java object is successfully created and persisted to
the database, and it gets the ID value set from the ORM tool
(Hibernate). I suspected that then the dataservice notifies the Flash
client that a new object exists, and that it should display it. My
assumption was that the managed Item object would then have the newly
generated ID instead of the default '0' value.

I have the feeling I'm probably not doing things in the correct order
or missing a crucial piece of information. How is one supposed to
persist a managed object via createItem() and put that into a
DataGrid? Does any article exist that showcases this situation? I've
perused the Flex docs extensively, but did not find a good example
that helped me resolve my problem.

Thanks in advance,
Benno Kittelmann

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

Reply via email to