Hi, i try to update an existing data object but the server response with error:
Cannot persist object. Property ‘objectId’ must be set by the server. Make sure the property is not initialized when saving new object
and my code is:
myData = Backendless.Data.Of(Of myDataClass).Save(myData)
myData.objectId is not null, i nned to update myData on server.
thanks for Help Ale
Hi Alessandro,
Are you using the latest build of the Backendless SDK for .NET ?
Regards,
Mark
Hi Mark,
Yes i think is the latest, i have downloaded it from GitHub “https://github.com/Backendless/.NET-SDK”.
Thanks
Hi Alessandro,
Could you please make sure “objectId” is declared as a get/set property, like this:
public String objectId { get; set; }
Regards,
Mark
Hi Mark,
I use VB.NET and i have two type of error:
-
with the variable declared like:
Public ReadOnly objectId As String
the error is:
{“java.lang.ClassCastException”}
-
with the variable declared:
Public objectId as String or Public objectId as String = “”
the error is:
Cannot persist object. Property ‘objectId’ must be set by the server
thanks
Ale
Hi Ale,
Here’s what code converters between C# and VB.Net suggest:
C# Code:
public class Foo
{
public string objectId {get;set;}
}
Corresponding VB.net code:
Public Class Foo
Public Property objectId() As String
Get
Return m_objectId
End Get
Set
m_objectId = Value
End Set
End Property
Private m_objectId As String
End Class
Hi Mark,
sorry for my insistence, but with the get and set method (that you have suggest) the response from server is:
{“java.lang.ClassCastException”}
Thanks Ale
Just tried this and it worked without any problems:
Public Class Person
Public Property name() As [String]
Get
Return m_name
End Get
Set(value As [String])
m_name = Value
End Set
End Property
Private m_name As [String]
Public Property objectId() As [String]
Get
Return m_objectId
End Get
Set(value As [String])
m_objectId = Value
End Set
End Property
Private m_objectId As [String]
End Class
Code to update person:
Dim person As New Person()
person.name = "Joe"
person.objectId = "9EB6D79B-E76D-5016-FFB6-0F37CB865400"
BackendlessAPI.Backendless.Data.[Of](Of Person)().Save(person)
Hi Mark,
Ok, if i create new instance of Class with the same objectId the response is OK. But if i try to save the same instance then i have loaded from the server i got an error. Why?
Thanks Ale
What does the class where objectId is declared look like?
I do not know if I understand the question. I load the object “person” from server, than i modify some parameter like name and finally i save the “person” (the same instance of Person) and i got an Error.
I just wanted to see what your version of the Person class looks like.
i have created an a test class with only the name string parameter and objectId
Could you please post that class here?
CLASS:
Public Class ANAGRAFICA_INTERVENTI
Public Property COSTO() As [String]
Get
Return m_COSTO
End Get
Set(value As [String])
m_COSTO = value
End Set
End Property
Private m_COSTO As [String]
Public Property objectId() As [String]
Get
Return m_objectId
End Get
Set(value As [String])
m_objectId = value
End Set
End Property
Private m_objectId As [String]
End Class
I took your class and wrote the following program:
'SAVE FIRST OBJECT
Dim testObj As New ANAGRAFICA_INTERVENTI()
testObj.COSTO = "test value"
BackendlessAPI.Backendless.Data.[Of](Of ANAGRAFICA_INTERVENTI)().Save(testObj)
'FIND FIRST OBJECT
Dim firstObj As ANAGRAFICA_INTERVENTI = BackendlessAPI.Backendless.Data.[Of](Of ANAGRAFICA_INTERVENTI)().FindFirst()
'SAVE/UPDATE FIRST OBJECT
firstObj.COSTO = "different value"
BackendlessAPI.Backendless.Data.[Of](Of ANAGRAFICA_INTERVENTI)().Save(firstObj)
The program ran just fine. Here’s the result in console:
http://support.backendless.com/public/attachments/84c0e330335da5d63cabe4383fbf2111.jpg</img>
Hi,
have you try to load many objects with an a query and save one of the object result?
If yes, can you pos a code?
Ale
Yes, I have. Here’s the result:
'GET OBJECTS
Dim myObjects As BackendlessAPI.Data.BackendlessCollection(Of ANAGRAFICA_INTERVENTI)
myObjects = BackendlessAPI.Backendless.Data.[Of](Of ANAGRAFICA_INTERVENTI)().Find()
'SAVE/UPDATE FIRST OBJECT
Dim firstObject As ANAGRAFICA_INTERVENTI = myObjects.Data.Item(0)
firstObject.COSTO = "UPDATED VALUE"
BackendlessAPI.Backendless.Data.[Of](Of ANAGRAFICA_INTERVENTI)().Save(firstObject)
http://support.backendless.com/public/attachments/64449c1e06148b1061a3ea5c24f84bdc.jpg</img>
Sorry mark,
if i try this not work:
'GET
Dim query As New BackendlessDataQuery()
myObjects = BackendlessAPI.Backendless.Data.Find(Of ANAGRAFICA_INTERVENTI)(query)
'SAVE/UPDATE FIRST OBJECT
Dim firstObject As ANAGRAFICA_INTERVENTI = myObjects.Data.Item(0)
firstObject.COSTO = “new value”
BackendlessAPI.Backendless.Data.[Of](Of ANAGRAFICA_INTERVENTI)().Save(firstObject)
Which part of it does not work?