How to delete record in activejdbc with no primary key?

418 views Asked by At

My table does not have a primary key. So when I try to delete a record

Table t = Table.findFirst("col = ?", var);
t.delete();

I get below exception. Any directions?

org.javalite.activejdbc.DBException: java.sql.SQLSyntaxErrorException: ... "ID": invalid identifier

1

There are 1 answers

0
ipolevoy On BEST ANSWER

ActiveJDBC does require an PK to operate. In case like yours, you need to override the delete() method, form a query that identifies your record, and call Base.exec() or DB.exec() methods internally. For clues on implementing, see the original Model#delete() method. Do the same, but only generate a different query.