This section shows how to select objects from the database using SelectQuery.
It was shown before how to persist new objects. Cayenne queries are used to access already saved objects. The primary query type used for selecting objects is SelectQuery. It can be mapped in CayenneModeler or created via the API. We'll use the later approach in this section. We don't have too much data in the database yet, but we can still demonstrate the main principles below.
- Select all paintings (the code, and the log output it generates):
- Select paintings that start with "gi", ignoring case (read more about qualifier Expressions and ExpressionFactory here:
- Select all paintings done by artists who were born more than a 100 years ago (demonstrating using Expression.fromString(..) instead of ExpressionFactory):
Next Step: Tutorial Delete