mongo-hibernate
Copilot instructions19 starsChanged 4 months agoApache-2.0View on GitHub
This repository is the MongoDB Extension for Hibernate ORM — a Hibernate dialect and JDBC adapter that lets applications use MongoDB as their database. It works by translating Hibernate's internal SQL AST into a MongoDB aggregation pipeline expressed in MQL (MongoDB Query Language). Copilot reviewers repeatedly make false, high-severity claims about how a given HQL/JPQL query is translated into MQL, because they reason from general MongoDB folklore instead of from how this translator actually behaves. This document exists to prevent…
In this repository4 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- add-hql-to-mql-translationSkill
- reviewing-pull-requestsSkill
The file
We split this copilot-instructions.md into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 82
Ground every claim in the code: Before asserting "this HQL translates to X", point at the visitor method in AbstractMqlTranslator (or the …
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
GitHub Copilot Instructions
This repository is the MongoDB Extension for Hibernate ORM — a Hibernate dialect and JDBC adapter that lets applications use MongoDB as their database. It works by translating Hibernate's internal SQL AST into a MongoDB aggregation pipeline expressed in MQL (MongoDB Query Language).
Copilot reviewers repeatedly make false, high-severity claims about how a given HQL/JPQL query is translated into MQL, because they reason from general MongoDB folklore instead of from how this translator actually behaves. This document exists to prevent that. Read the "HQL → MQL translation" section below before commenting on any translation, expected-MQL string, or test assertion.
How translation works
- The translator is a visitor over Hibernate's SQL AST. The entry points are
internal/translate/AbstractMqlTranslator(shared logic),SelectMqlTranslator(SELECT → aggregation pipeline) andMutationMqlTranslator(INSERT / UPDATE / DELETE). - The translator builds the project's own MongoDB AST under
internal/translate/mongoast/(stages, filters, expressions). That AST is then serialized to BSON. Expected-MQL strings in tests are the serialization of this AST — they are deterministic, not heuristic. - A SELECT becomes a pipeline assembled in this fixed order:
$lookup/$unwind(joins) →$match→$sort→$skip/$limit→$project(seeAbstractMqlTranslatorwherestagesis assembled). Do not claim a stage appears in a different position unless the code shows it. - Anything the translator cannot express throws
FeatureNotSupportedException. Unsupported shapes that are planned carry aTODO-HIBERNATE-NNNmarker with a Jira link. A query that throws is not a silent miss — do not flag it as one.
HQL → MQL translation: authoritative operator mapping
These mappings are fixed in code. When reviewing, treat them as ground truth. Do not claim a query is translated differently, and do not raise MongoDB null/missing/BSON-ordering semantics as a correctness bug against these mappings — that behavior is intentional and matches the operators below.
Nullness predicates (visitNullnessPredicate)
| HQL | MQL filter |
field is null | { field: { $eq: null } } |
field is not null | { field: { $ne: null } } |
is not nullis translated to$ne: null— this is correct and intended. Do not claim it "should" be$nor/$exists, and do not report it as a critical bug that$ne: nullor$eq: nullalso match missing fields. Matching missing fields is the accepted, documented behavior of this translator.not (field is null)goes throughvisitNegatedPredicate, which wraps the inner filter in$nor.$nor: [{ field: { $eq: null } }]andfield is not null($ne: null) are produced by two different code paths and are not required to be byte-identical. Do not file a bug that they differ.
Comparison predicates (createAstComparisonFilterOperator)
Comparison operators map 1:1 onto MQL query operators:
| HQL / SQL operator | MQL |
= | $eq |
<> / != | $ne |
< | $lt |
<= | $lte |
> | $gt |
>= | $gte |
- These emit the raw MongoDB comparison operators. General BSON-comparison-order behavior (e.g.
how
$gt/$gtecompare againstnullor across BSON types) is the database's semantics, not a bug in this translator. Do not predict specific result sets for comparisons againstnulland present them as evidence of a defect.
Boolean expression predicates (visitBooleanExpressionPredicate)
- A bare boolean field
flag→{ flag: { $eq: true } }; negated →{ flag: { $eq: false } }.
Logical connectives
and→$and,or→$or(visitJunction),not (...)→$nor(visitNegatedPredicate).
Review guidance — do this
- Ground every claim in the code. Before asserting "this HQL translates to X", point at the
visitor method in
AbstractMqlTranslator(or the relevantmongoastnode) that produces X. If you cannot, do not assert it. - Trust the expected-MQL strings in tests. They are the serialized AST. If an expected string looks surprising, the resolution is almost always that your mental model of MongoDB defaults differs from what this translator deliberately emits — not that the test is wrong.
- Do not raise database-level MongoDB semantics as translator bugs. How MongoDB matches
null/missing or orders BSON types is out of scope for a translation review unless the code is clearly emitting the wrong operator. FeatureNotSupportedExceptionis a feature. Unsupported shapes are meant to throw; aTODO-HIBERNATE-NNNmarker means it is tracked. Do not flag these as incomplete/unsafe.- Severity discipline. Reserve "critical"/"high" for a demonstrable defect you can tie to a specific line. Speculative semantic concerns are, at most, low-severity questions.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

