Hi,
I'm having issues with a Joined-Subclass.
There is an object called Task and a subclass of this class is AssignedTask.
If I create an instance of Task, save it, then delete it and check the logs I see that during the deletion process it calls
"DELETE FROM AssignedTask WHERE TaskID = $p$"
All well and good.
However, if I create an instance of AssignedTask, save it, then delete it I get an exception with the message: "Row was updated or deleted by another transaction".
Returning to my log file I see:
"DELETE FROM AssignedTask WHERE TaskID = $p$"
"DELETE FROM AssignedTask WHERE TaskID = $p$"
It's been called twice thus leading to this problem.
I tried to incorperate into the delete mechanism.........
Code:
public class AssignedTask
{
...
public override void Delete()
{
Task task = data.GetObject(typeof(Task), this.ID) as Task;
task.Delete();
}
...
}
// data.GetObject is as follows.
public TTObject GetObject(Type type, int id)
{
IList list = null;
ITransaction tx = null;
lock(sessionLock)
{
try
{
tx = session.BeginTransaction();
list = session.Find(String.Format("FROM {0} AS a "+
WHERE a.ID = ?",
type.ToString()),
id, TypeFactory.GetInt32Type());
tx.Commit();
}
catch (Exception ex)
{
if(tx != null)
tx.Rollback();
throw ex;
}
}
if(list.Count == 0)
{
return null;
}
else if(list.Count > 1)
{
throw new InvalidOperationException
("A Search on ID returned more than one TTObject in DataStore.GetObject");
}
else
{
return (TTObject)list[0];
}
}
However I find that when I try to get this task object via the GetObject method it instead returns to me an instance of AssignedTask instead of an instance of task.
I assume this is because it sees the entry in AssignedTask and assumes the object must be an AssignedTask.
The subclass mapping in Task.xml.hbm is as follows:
Code:
<joined-subclass table="AssignedTask" name="TTLibrary.Object.AssignedTask, TTLibrary">
<key column="TaskID"/>
<property name="X" column="X" type="Int32"/>
<many-to-one class="TTLibrary.Object.User, TTLibrary" column="UserID" foreign-key="UserID" name="User" cascade="none"/>
</joined-subclass>
Could someone please point me towards the right direction on this one because i'm really struggling.
Many thanks in advance if you can. :)