First comment about web site, its look very professional to me.
I am using AtomsFramework 1.22 with the MsSql database. I've read though "How Do I Persist Inheritance?" in the FAQ.
I have the following two classes: DomainObject and Party. Each of them has the corresponding tables with the same name in the database. Party inherits from the DomainObject that inherits from the CPersistentObject.
When I call Save() method on the Party object, party properties are saved correctly, but DomainObject properties are not saved (DomainObject is not saved to the database).
Here's my code and xml file:
// Party object
public class Party: DomainObject
{
private string name;
private string address;
public Party()
{
}
public override AToMSFramework.CPersistentObject getNewObject()
{
return new Party();
}
public override bool IsValid()
{
return true;
}
public string Name
{
get
{
return name;
}
set
{
name = value;
SetDirtyFlag();
}
}
public string Address
{
get
{
return address;
}
set
{
address = value;
SetDirtyFlag();
}
}
} // Party object end
// DomainObject
public class DomainObject : CPersistentObject
{
protected int test1;
public DomainObject()
{
}
public override AToMSFramework.CPersistentObject getNewObject()
{
return new DomainObject();
}
public override bool IsValid()
{
return true;
}
public int Test1
{
get
{
return test1;
}
set
{
test1 = value;
SetDirtyFlag();
}
}
} // DomainObject end
public class MainClass
{
public static void Main()
{
CPersistenceBroker pbroker = new CPersistenceBroker();
pbroker.init();
Party p1 = new Party();
p1.Name = "Name 123";
p1.Address = " Address 123";
p1.Save();
}
}
I have debugged p1.Save () method, and in the getObjectByClassMap function I have found that property/flag IsDirty is set to False to prevent recursion. That flag value is copied (in the getObjectByClassMap function) from the Party object to the DomainObject (its super class). Because this flag is already false DomainObject is not saved to the database.
How to define my classes in the xml file (or in the code) to accomplish that all (two) objects are saved to the database?
Thanks in advance
Sanjin Matusan
Save()
...
Function getObjectsToSave(ByVal obj As CPersistentObject, ByVal includeBaseObject As Boolean) As Stack
...
If includeBaseObject Then stack.Push(obj)
'Clear the dirty flag to prevent recursion in the class structure causing an infinite loop
obj.IsDirty = False
...
Function getObjectByClassMap(ByVal classMap As CClassMap) As CPersistentObject
...
'copy the OriginalModifiedDate and the ModifiedDate from the child to the parent.
'if we don't do this the object won't get saved correctly on subsequent calls.
obj.setAttributeValue("ModifiedDate", Me.getValueByAttribute("ModifiedDate"))
obj.m_originalModDate = Me.getValueByAttribute("OriginalModifiedDate")
obj.m_dirty = Me.m_dirty // for DomainObjct value of the Party property m_dirty is copied
...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Regarding the problem you have, are you able to get the latest code from CVS and try it with that first? I've had some problems with 1.22 that have been fixed in the last few weeks, so I'd like to see if you still have the problem before I look into it.
Thanks,
Richard.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The Nunit tests should be much more comprehensive, but it's a bit like going to the dentist. You know you _should_ do it, but you never seem to find the time to actually do it.
- Richard.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
First comment about web site, its look very professional to me.
I am using AtomsFramework 1.22 with the MsSql database. I've read though "How Do I Persist Inheritance?" in the FAQ.
I have the following two classes: DomainObject and Party. Each of them has the corresponding tables with the same name in the database. Party inherits from the DomainObject that inherits from the CPersistentObject.
When I call Save() method on the Party object, party properties are saved correctly, but DomainObject properties are not saved (DomainObject is not saved to the database).
Here's my code and xml file:
// Party object
public class Party: DomainObject
{
private string name;
private string address;
public Party()
{
}
public override AToMSFramework.CPersistentObject getNewObject()
{
return new Party();
}
public override bool IsValid()
{
return true;
}
public string Name
{
get
{
return name;
}
set
{
name = value;
SetDirtyFlag();
}
}
public string Address
{
get
{
return address;
}
set
{
address = value;
SetDirtyFlag();
}
}
} // Party object end
// DomainObject
public class DomainObject : CPersistentObject
{
protected int test1;
public DomainObject()
{
}
public override AToMSFramework.CPersistentObject getNewObject()
{
return new DomainObject();
}
public override bool IsValid()
{
return true;
}
public int Test1
{
get
{
return test1;
}
set
{
test1 = value;
SetDirtyFlag();
}
}
} // DomainObject end
and xml:
<class name="DomainObject" table="DomainObject" database="erp1">
<attribute name="OIDValue" column="oid" key="primary"/>
<attribute name="CreatedDate" column="CreatedDate" timestamp="true"/>
<attribute name="ModifiedDate" column="ModifiedDate" timestamp="true"/>
<attribute name="Test1" column="Test1"/>
</class>
<class name="Party" table="Party" superclass="DomainObject" database="erp1">
<attribute name="OIDValue" column="oid" key="primary" reference="OIDValue"/>
<attribute name="CreatedDate" column="CreatedDate" timestamp="true"/>
<attribute name="ModifiedDate" column="ModifiedDate" timestamp="true"/>
<attribute name="Name" column="Name"/>
<attribute name="Address" column="Address"/>
</class>
Main program:
public class MainClass
{
public static void Main()
{
CPersistenceBroker pbroker = new CPersistenceBroker();
pbroker.init();
Party p1 = new Party();
p1.Name = "Name 123";
p1.Address = " Address 123";
p1.Save();
}
}
I have debugged p1.Save () method, and in the getObjectByClassMap function I have found that property/flag IsDirty is set to False to prevent recursion. That flag value is copied (in the getObjectByClassMap function) from the Party object to the DomainObject (its super class). Because this flag is already false DomainObject is not saved to the database.
How to define my classes in the xml file (or in the code) to accomplish that all (two) objects are saved to the database?
Thanks in advance
Sanjin Matusan
Save()
...
Function getObjectsToSave(ByVal obj As CPersistentObject, ByVal includeBaseObject As Boolean) As Stack
...
If includeBaseObject Then stack.Push(obj)
'Clear the dirty flag to prevent recursion in the class structure causing an infinite loop
obj.IsDirty = False
...
Function getObjectByClassMap(ByVal classMap As CClassMap) As CPersistentObject
...
'copy the OriginalModifiedDate and the ModifiedDate from the child to the parent.
'if we don't do this the object won't get saved correctly on subsequent calls.
obj.setAttributeValue("ModifiedDate", Me.getValueByAttribute("ModifiedDate"))
obj.m_originalModDate = Me.getValueByAttribute("OriginalModifiedDate")
obj.m_dirty = Me.m_dirty // for DomainObjct value of the Party property m_dirty is copied
...
Hi Sanjin,
Thanks for the feedback on the web site :-)
Regarding the problem you have, are you able to get the latest code from CVS and try it with that first? I've had some problems with 1.22 that have been fixed in the last few weeks, so I'd like to see if you still have the problem before I look into it.
Thanks,
Richard.
Yes , with cvs version (1.23) the DomainObject is saved to the database.
Thanks :)
P.S. Maybe to implement nunit test case for persisting inheritance
Yes with the last cvs version (i.e. 1.23) DomainObject is saved to the database
Thanks :)
P.S.
Maybe to implement nunit test case for persisting inheritance?
I'm glad it's working now.
The Nunit tests should be much more comprehensive, but it's a bit like going to the dentist. You know you _should_ do it, but you never seem to find the time to actually do it.
- Richard.