agentleFS
MongoDBKnown publishermongodb/mongo-hibernate/AGENTS.md

mongo-hibernate

AGENTS.md19 starsChanged 4 months agoApache-2.0View on GitHub

MongoDB Extension for Hibernate ORM — a Hibernate dialect and JDBC adapter that lets applications use MongoDB as their database. Translates Hibernate's SQL AST into MongoDB aggregation pipelines. Integration tests require MongoDB replica set running at localhost:27017 with --enableTestCommands=1. Override the connection string via jakarta.persistence.jdbc.url in src/integrationTest/resources/hibernate.properties. The replica set has typically already been started by the developer and is available. Integration tests run concurrently within a single JVM via JUnit parallel execution (configured in src/integrationTest/resources/junit-platform.properties: test classes run concurrently,…

  • Installs packages
  • Sends data out
  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.

    Of the AGENTS.md files we read, the 33,398 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repository4 other files it gives its agents.

The file

We split this AGENTS.md into the rules it gives an agent

5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Check that the jira CLI is installed at /opt/homebrew/bin/jira.

    line 56
  2. Very specific:

    If jira commands fail with a missing configuration error, ask the developer to run jira init (link: https://jira.mongodb.org, login: their …

    line 70
  3. Very specific:

    If TOKEN is empty, ask the developer to create a Personal Access Token at https://jira.mongodb.org/tokens and add it to the keychain …

    line 72
  4. Distinctive:

    Integration test registry setup: every integration test that builds a Hibernate SessionFactory/ServiceRegistry through the testing …

    line 106
  5. Distinctive:

    Checked-in docs: Use repo-relative paths, not developer-local absolute paths (e.g.

    line 110

≈ “Common” is an estimate: at least 1 in 5 of the 43,423 AGENTS.md 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

AGENTS.md

This file provides guidance to AI coding agents (Claude Code, Gemini CLI, etc.) when working with code in this repository.

What This Project Is

MongoDB Extension for Hibernate ORM — a Hibernate dialect and JDBC adapter that lets applications use MongoDB as their database. Translates Hibernate's SQL AST into MongoDB aggregation pipelines.

Build and Test Commands

./gradlew build                                        # full build including unit tests and checks
./gradlew test                                         # unit tests only
./gradlew integrationTest                              # integration tests (requires MongoDB, see below)
./gradlew test --tests ClassName                       # single test class
./gradlew integrationTest --tests ClassName            # single integration test class
./gradlew spotlessApply                                # auto-format code
./gradlew spotlessCheck                                # check formatting without applying

Integration tests require MongoDB replica set running at localhost:27017 with --enableTestCommands=1. Override the connection string via jakarta.persistence.jdbc.url in src/integrationTest/resources/hibernate.properties. The replica set has typically already been started by the developer and is available.

Integration test parallelism

Integration tests run concurrently within a single JVM via JUnit parallel execution (configured in src/integrationTest/resources/junit-platform.properties: test classes run concurrently, methods within a class stay on one thread). Each top-level test class is isolated to its own database, assigned once per class and memoized — see MongoExtension.configurationContributorForClass, applied by MongoServiceRegistryProducer and by the few tests that bootstrap Hibernate directly. There is no per-thread state; captured commands are likewise partitioned by database name in MongoExtension.

Tests that manipulate mongod-global state — e.g. the failCommand fail point, a single shared server-side switch — must not run concurrently with anything; annotate them @Isolated. There is a single integrationTest task running one JVM, so --tests works normally; the JUnit thread count is fixed in junit-platform.properties (the fastest value is machine-specific and does not track core count).

Architecture

Layers

dialect/MongoDialect — Entry point. Registers type mappings, custom functions, and supplies the query translator to Hibernate.

JDBC adapter (jdbc/MongoConnection, MongoStatement, MongoResultSet) — Implements JDBC interfaces over the MongoDB Java Driver. Manages ClientSession lifecycle; MongoResultSet maps BSON documents to JDBC rows.

Translators (internal/translate/) — Convert Hibernate's SQL AST to MQL:

  • SelectMqlTranslator — visitor pattern, emits an aggregation pipeline ($match → $sort → $skip/$limit → $project)
  • MutationMqlTranslator — INSERT, UPDATE, DELETE

Type system — MongoStructJdbcType (embeddables / @Struct), MongoArrayJdbcType (collections), ObjectIdJavaType/ObjectIdJdbcType (ObjectId support).

MongoDB AST

internal/translate/mongoast/ contains the project's own AST for MongoDB pipeline stages, filters, and expressions. The translators build this AST, which is then serialized to BSON by the JDBC adapter.

Module Boundaries

The Java module (com.mongodb.hibernate) exports only cfg, cfg.spi, and annotations. Everything under internal/ is implementation-private.

Jira

Project: HIBERNATE at https://jira.mongodb.org/browse/HIBERNATE

Check that the jira CLI is installed at /opt/homebrew/bin/jira. If not, ask the developer to install it:

brew install ankitpokhrel/jira-cli/jira-cli

The jira CLI handles basic issue operations (jira issue view, jira issue edit, jira issue move, etc.).

Retrieve the bearer token from the macOS Keychain:

TOKEN=$(security find-generic-password -s "jira-cli" -w)

If jira commands fail with a missing configuration error, ask the developer to run jira init (link: https://jira.mongodb.org, login: their MongoDB email).

If TOKEN is empty, ask the developer to create a Personal Access Token at https://jira.mongodb.org/tokens and add it to the keychain (security add-generic-password -s "jira-cli" -a "their.name@mongodb.com" -w "<token>"). This assumes they are on a Mac. If not, figure out the Linux or Windows equivalent.

For operations the CLI doesn't support natively (e.g. re-ordering/ranking issues within an epic), use curl with $TOKEN and the Jira Agile REST API, e.g.:

# Re-order: move HIBERNATE-XXX to rank before HIBERNATE-YYY
curl -s -X PUT \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"issues":["HIBERNATE-XXX"],"rankBeforeIssue":"HIBERNATE-YYY"}' \
  "https://jira.mongodb.org/rest/agile/1.0/issue/rank"

Architecture Invariants

ARCHITECTURE.md documents the contracts that new code has to respect: visitor dispatch and the AstVisitorValueDescriptor protocol, why translation must not use a parallel recursive descent, compact find syntax vs. $expr in $match, clause-position parity, the aggregation stage order, and the FeatureNotSupportedException vs. AssertionError failure contract. Read it before designing or reviewing a translation change.

Task-Specific Skills

  • Adding HQL-to-MQL translation support --- .claude/skills/add-hql-to-mql-translation/SKILL.md
  • Reviewing a pull request --- .claude/skills/reviewing-pull-requests/SKILL.md

Code Style

  • JDK: Java 17 (matches CI). Verify with java -version before building. An .sdkmanrc is provided if the developer uses sdkman.
  • Formatter: Spotless + Palantir Java Format. Always run ./gradlew spotlessApply before committing.
  • Nullness: JSpecify annotations enforced by NullAway (via Error Prone at compile time). Annotate all API boundaries.
  • Line length: 120 characters.
  • Test class naming: suffix Tests, not Test.
  • Integration test registry setup: every integration test that builds a Hibernate SessionFactory/ServiceRegistry through the testing framework must implement MongoServiceRegistryProducer (in com.mongodb.hibernate.junit). It strips the SharedDriverManagerConnectionProvider that Hibernate's test framework injects, which would otherwise trip the auto-configured connection provider.
  • Checked-in docs: Use repo-relative paths, not developer-local absolute paths (e.g. /Users/name/...), when referencing files in design specs, plans, or other markdown committed to the repo — these are read on GitHub by people whose checkouts differ from yours.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.