Bala
Bala

Reputation: 11264

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

Upvotes: 0

Views: 424

Answers (1)

ipolevoy
ipolevoy

Reputation: 5518

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.

Upvotes: 1

Related Questions