Limiting Columns Selected with ActiveJDBC

252 views Asked by At

How can I limit the number of columns being fetched by ActiveJDBC? Is there something similar to Hibernate Projections in ActiveJDBC?

1

There are 1 answers

0
ipolevoy On BEST ANSWER

Technically speaking, ActiveJDBC is an ORM, and as such will fetch all attributes related to a model (all columns from table). If a model instance is does not have them all, than the 'O' is missing from the ORM :). In other words, it stops being an object that represents a relation.

If this is absolutely what you need to do, then you can do the following:

List<Person> retirees = Person.findBySql("select first_name, last_name from people where age > ? ", 65);

This way, the query will populate only the first_name and last_name attributes. In general, you can pass any query to the findBySql(), and the model will read values whose names match that model's attribute names.