Search code examples
activejdbc

How to delete record in activejdbc with no primary key?


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


Solution

  • 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.