The way you described it is the right way: context.deleteObject(..); context.commitChanges(). So I guess you'll need to check the code to see why nothing gets deleted. Maybe nothing gets selected in the first place? Does select query prints a result count that is greater than zero?

Andrus

P.S. Looks like your email address is not subscribed to the list, so you will not receive replies not cc'd to you directly.


On Jun 27, 2006, at 10:43 AM, Pirola Davide wrote:


Hi all,
i have a problem with the "DELETE" operation.
I have "TimerTask" that every 5 minutes load data from an Oracle Database and insert them into HsqlDb (locale to the application).
So every 5 minutes my table on HSQLDB receive some "INSERT" commands.
I do this with this peace of code:

for (....all my objects)
{
        datacontext.registerNewObject(myobject)
        datacontext.commitChanges()
}


But, first of all, i need to "DELETE" data that are older than 60 minutes.
So i try to delete these data in this way:

1) i execute a SELECT query on the table (HSQLDB)getting all record that are older than 60 minutes.

2) for every object retrived, i execute "datacontext.delete(myobject)"

3) at the end i call "datacontext.commitChanges()".

I expect to see some "DELETE" query over my HSQLDB... but nothing appen :-S
So no data are deleted... and my database grow :(

There is another way for doing this task... execute directly the delete query:
 "DELETE FROM mytable WHERE DATEDIFF('mi',INSERT_DATE, NOW()) > 60 "

but..in this way.. the data in the table are deleted, but cayenne takes in the Heap (Old Gen) the reference of the old objects... so the garbage collector can't remove them from memory.(memory leak)

So question is... which is the right way to delete data in a table using cayenne?

Thanks,
Davide





Reply via email to