/apache-cayenne-6:cayenne-queryfrom apache-cayenne-6
Writes idiomatic Cayenne 6.0 queries: ObjectSelect, SQLQuery, expressions, prefetching, pagination, aggregates, and raw SQL. Activated when users need to fetch, filter, join, or paginate data via Cayenne.
Ships in apache-cayenne-6. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Write idiomatic Cayenne 6.0 queries — ObjectSelect, SQLQuery, expressions, prefetch, pagination, aggregates.
${CLAUDE_PLUGIN_ROOT}/references/query-api.md — every query mechanism with examples (ObjectSelect incl. column queries, SQLQuery, Expression, selecting by id).This plugin is for Cayenne 6.0. Look at the project's build file first: if it depends on Cayenne 5.x, the API below
doesn't apply. Tell the user to install apache-cayenne-5@apache-cayenne instead, and stop.
| Intent | Use |
|---|---|
| Fetch one or more entities matching criteria | ObjectSelect.query(Cls.class).where(...).select(ctx) |
| Fetch by primary key | ObjectSelect.query(Cls.class).byId(pk).selectOne(ctx) |
| Aggregate (count, sum) | ObjectSelect.query(Cls.class).selectCount(ctx) or ObjectSelect.query(Cls.class).columns(..) with aggregate functions |
| One or a few columns only (DTO-style) | ObjectSelect.query(Cls.class).columns(Cls.NAME, Cls.AGE).select(ctx) |
| Raw SQL with parameter binding | SQLQuery.query(Cls.class, "SELECT ...").params(...).select(ctx) |
| Insert/update/delete bulk | SQLQuery.query("UPDATE ...").update(ctx) |
| Reused named query stored in DataMap | XML <objectQuery> / <sqlQuery> / <procedureQuery> (see ${CLAUDE_PLUGIN_ROOT}/references/datamap-schema.md) loaded via NamedQuery |
byId(..) / byIds(..)When the user is fetching entities by PK, use the ObjectSelect id shorthands rather than
ObjectSelect.where(PK.eq(...)):
Artist a = ObjectSelect.query(Artist.class).byId(42).selectOne(ctx);
List<Artist> list = ObjectSelect.query(Artist.class).byIds(1, 2, 3).select(ctx);
Both accept a scalar, a Map<String, Object> of PK column → value (the form for composite PKs), or an
ObjectId, and byIds(..) may mix them. SelectById no longer exists — never generate it. If the object is likely
already in the context and no query customization is needed, ctx.objectForPK(Artist.class, 42) resolves it
from the session cache without a SQL query.
Property constantscgen generates Property<T> constants on each entity superclass. Use them — they're type-checked at compile time:
ObjectSelect.query(Artist.class)
.where(Artist.ARTIST_NAME.likeIgnoreCase("p%"))
.and(Artist.DATE_OF_BIRTH.between(d1, d2))
.select(ctx);
Only fall back to ExpressionFactory.matchExp("artistName", ...) or Expression.fromString(...) when:
query-api.md lists all common predicate methods on Property.
When the query traverses a relationship in a loop, always add a prefetch to avoid N+1:
// Bad — fires one query per artist when paintings are accessed
for (Artist a : artists) { a.getPaintings().size(); }
// Good
List<Artist> artists = ObjectSelect.query(Artist.class)
.prefetch(Artist.PAINTINGS.disjoint())
.select(ctx);
Pick:
.joint() — to-one relationships, or to-many with small fan-out. Single SQL join..disjoint() — to-many, modest size. Two queries..disjointById() — to-many, very large parent set. Two queries, keyed by PKs.ObjectSelect.query(Artist.class)
.orderBy(Artist.ARTIST_NAME.asc())
.pageSize(50) // server-side pagination
.limit(1000)
.localCache() // per-context cache, or .sharedCache("group-name")
.select(ctx);
Use sharedCache for reference data (rarely changes, read often). Use pageSize to avoid loading entire result sets.
List<Artist> hits = SQLQuery.query(Artist.class,
"SELECT * FROM ARTIST WHERE ARTIST_NAME LIKE #bind($pattern)")
.params(Map.of("pattern", userInput + "%"))
.select(ctx);
Always use #bind($name) placeholders. Never concatenate user input into SQL. Cayenne's SQL templates use a Velocity-like directive syntax — see query-api.md for #bind, #bindEqual, #chain, and adapter-specific SQL with <sql adapterClass="...">.
#bind($name). Concatenation is a SQL injection vector and may also result in invalid syntax.selectOne when multiple may match. It throws. Use selectFirst if "any one" is okay..pageSize(n) or iterator() and process incrementally..prefetch(...).Expression.fromString(...) or ExpressionFactory.matchExp("fieldName", ...) for static queries. Prefer typed Property constants (Artist.ARTIST_NAME.eq(...)) — they catch typos at compile time and survive model refactors.ObjectContext.commitChanges() is required for changes to persist.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub apache/cayenne --plugin apache-cayenne-69 skills in this plugin
/cayenne-cgenUse this skill whenever the user wants to (re)generate Cayenne entity Java classes from a DataMap. Trigger on phrases like 'generate Java classes', 'regenerate entities', 'run cgen', 'create the entity classes', 'why is the Artist class missing fields', 'where did the `_Abstract*` classes come from', 'sync the entity classes with the model', or any request to materialize Java from the DataMap. Also trigger as a follow-up after modeling changes (someone added an entity, attribute, or relationship and now the Java side is stale). This skill exclusively uses the `cgen_run` MCP tool — it does NOT use `mvn cayenne:cgen` or the Gradle cgen task./cayenne-db-importUse this skill when the user wants to import database schema metadata into a Cayenne DataMap — the *model/mapping only*, not names or Java classes. Trigger on phrases like 'reverse engineer the database', 'import the schema', 'generate a DataMap from my DB', 'add the new tables from the DB into the model', 'import the customer table', 'create entities from these tables', or any request to read database metadata to populate or update a DataMap's XML. This is the only way the DB layer of the model (DbEntity, DbAttribute, DbRelationship) gets created or changed, whatever the size — a full schema, a batch of tables, or a single new table, column or FK. Hand-editing the DB layer in `cayenne-modeling` is allowed only when the user has explicitly said they do not use DB import; Object-layer edits (ObjEntity, ObjAttribute, ObjRelationship) always belong in `cayenne-modeling`. IMPORTANT — scope: this imports the mapping ONLY; it does not clean up the Object-layer names or (re)generate Java classes. When the user wants their whole project brought in line with the DB ('sync my project with the database', 'my schema changed, update everything', 'update my entities/classes from the DB'), that is the end-to-end `cayenne-full-db-sync` skill, which runs this import and then name cleanup and class generation. To regenerate classes alone use `cayenne-cgen`. The skill runs reverse engineering directly via the `dbimport_run` MCP tool when a DBConnector is already configured; otherwise it opens the CayenneModeler GUI via `open_project` to configure the connection first./cayenne-full-db-syncUse this skill when the user wants to bring their WHOLE Cayenne project in line with the database in one shot — the mapping, the Object-layer names, and the generated Java classes together. This is the end-to-end 'sync with the DB' workflow, and it orchestrates three skills in order: `cayenne-db-import` (import schema metadata into the DataMap) → `cayenne-model-naming` (polish the just-imported names) → `cayenne-cgen` (regenerate Java classes). Trigger on holistic phrases like 'sync my project with the database', 'sync with the DB', 'my schema changed, update everything', 'update my entities/classes from the database', 'reverse engineer and regenerate the classes', 'import the new tables and rebuild the entities', 'full DB sync', 'bring the model and classes up to date with the DB'. The distinguishing signal is scope: the user wants the whole project (mapping + names + Java code), not just one stage. For the *model/mapping only* (no name cleanup, no class generation) use `cayenne-db-import`; to (re)generate classes alone use `cayenne-cgen`; to clean names alone use `cayenne-model-naming`. Uses the `dbimport_run` and `cgen_run` MCP tools via the sub-skills; does NOT use Maven or Gradle goals./cayenne-modelerUse this skill when the user explicitly wants to open CayenneModeler (the GUI) on a Cayenne project, or when the modeling task is one the Modeler has to do — first-time DB connection setup for reverse engineering (delegated to cayenne-db-import), bulk relationship layout, multi-entity visual refactoring. Trigger on phrases like 'open the Modeler', 'open in CayenneModeler', 'launch the GUI', 'edit visually', 'show me the project in the Modeler'. Do NOT trigger for upgrading a project saved by an older Cayenne version — that's the cayenne-upgrade skill. Do NOT trigger as a fallback for ordinary a-la-carte XML edits — those belong in the cayenne-modeling skill, which is faster and doesn't require the user to context-switch./cayenne-modelingUse this skill whenever the user wants to edit, inspect, or extend the Cayenne ORM model in a project — adding or modifying entities, attributes, relationships, embeddables, named queries, stored procedures, or DataNodes. Trigger on phrases like 'add an ObjEntity', 'add a DbEntity', 'add a relationship', 'expose this column as an attribute', 'create a new DataMap', 'add a named query', 'create an embeddable', 'add a stored procedure', 'change the attribute type', 'mark this column as nullable', 'rename this entity', or any mention of a Cayenne `*.map.xml` or `cayenne-*.xml` file. Also trigger when the user references modeling concepts (ObjEntity, DbEntity, ObjAttribute, DbAttribute, ObjRelationship, DbRelationship, Embeddable, dbEntityName, deleteRule, dbAttributePath, dbRelationshipPath, defaultPackage) in the context of a Cayenne-using app. This is the *primary* skill for a-la-carte ORM model manipulation — direct XML edits, not the Modeler GUI. IMPORTANT — DB layer ownership: the DB layer (DbEntity, DbAttribute, DbRelationship) is owned by DB import and is NOT hand-edited by this skill, unless the user has explicitly said they do not use DB import for this project. Otherwise a DB-layer request, even for a single table or column, is routed to `cayenne-db-import`; this skill hand-edits the Object layer, queries, embeddables and config blocks./cayenne-model-namingUse this skill to clean up Object-layer names in a Cayenne DataMap — ObjEntity, ObjAttribute, and ObjRelationship names, plus DbRelationship names (the first-class unit of relationship cleanup — every FK has one whether or not an ObjRelationship was generated; the ObjRelationship name is synced to it when one exists) — so they read as descriptive, consistent Java. Trigger on phrases like 'clean up the model names', 'fix the entity names', 'these names look ugly', 'make the names descriptive', 'normalize the ObjEntity/attribute/relationship names', 'why is this relationship called team1', 'rename entities to be consistent', 'the import produced Gametype instead of GameType'. Invoke it on an explicit user request, or as a manual follow-up after a `cayenne-db-import` to polish the just-imported additions — it is never triggered automatically. IMPORTANT: this is a LIGHT polish pass — CayenneModeler's reverse-engineering already produces good names for the common case; only improve the specific things its deterministic algorithm cannot (run-together names with no separators like `gametype`, meaningless numbered names like `team1` from multiple relationships between two tables, and a common entity prefix that leaks into relationship names like `aaOrders`). Do NOT rewrite names that are already correct. This is Obj-layer naming polish; for structural model edits use `cayenne-modeling`, and for regenerating classes afterward use `cayenne-cgen`.Other plugins' skills for the same job