I am using db4o in a Java project. I want to create a prototype to get all the persons that are not married using querybyexample. The Person class has three attributes: name(String), age(int) and married(boolean), so I create the following prototype:
Person prototypePerson = new Person(null, 0, false);
Instead of getting not married persons, I get ALL the persons stored in the DB, both married and unmarried. Could I get unmarried persons using querybyexample or I should use native queries?
Basically query by example only checks fields which do not have the default value as query parameter. For boolean, 'false' is the default value, so in your example it will be skipped.
You could consider using a enum. Change the field to that enum. Like:
This makes your code more explicit what it means, and more extensible (like adding Widowed as status) and it should work with query by example. The query would be:
Person prototypePerson = new Person(null, 0, MaritalStatus.SINGLE);