1
votes

Let's say I have an ObjectBox entity like so:

@Entity
public class CountryEntity {

    @Id
    private long entityId;

    private String name;
    private float area;
    private int population;
    private String subRegion;
    private String region;
    private String code3;
    private String capitalCity;

    setters, getters }


and a query :

public ObjectBoxLiveData<CountryEntity> getAllCountries(){
       Box<CountryEntity> countryBox = boxStore.boxFor(CountryEntity.class);
       return new ObjectBoxLiveData<CountryEntity>(
               countryBox.query().order(CountryEntity_.name).build());
   }

This selects all countries. Is there a way to select only some "columns" eg. name and area for example and not the others?

Oftentimes I don't really need all columns but rather a subset and I feel pretty guilty about querying all that data unnecessarily.

Thank you!

1

1 Answers

1
votes

Don't worry too much. ObjectBox creates objects extremely fast (maybe 10x faster than other solutions). So unless you are carrying e.g. large binary objects you should be fine.

To query single properties, you may have seen property queries.

Otherwise there's this feature request you may want to vote for: https://github.com/objectbox/objectbox-java/issues/348