Models use ActiveJDBC, a lightweight ORM that follows the ActiveRecord pattern. A model maps directly to a database table — no configuration needed.
@Table("articles")
public class Article extends Model {
public String getTitle() { return getString("title"); }
public String getContent() { return getString("content"); }
public Integer getStatus() { return getInteger("status"); }
public void setTitle(String title) { set("title", title); }
public void setContent(String content) { set("content", content); }
public void setStatus(Integer status) { set("status", status); }
}
By convention, ActiveJDBC maps Article to the articles table automatically. Use @Table to override when your table name doesn't follow the convention.
// Create
Article article = new Article();
article.setTitle("My title");
article.setContent("My content");
article.saveIt();
// Retrieve
Article article = Article.findById(1);
LazyList<Article> articles = Article.findAll();
LazyList<Article> published = Article.where("status = ?", 1);
// Update
article.setTitle("New title");
article.saveIt();
// Delete
article.delete();
public class Article extends Model {
// belongs to
public User getAuthor() {
return parent(User.class);
}
// has many
public LazyList<Comment> getComments() {
return get(Comment.class, "article_id = ?", getId());
}
}
For the full list of query methods, callbacks, and associations, refer to the official ActiveJDBC documentation →