jakartaee / jakartaee/persistence

[Feature Request] Add config property to auto-detect bidirectional relationships without mandatory mappedBy

Open
#1,145 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
267
Forks
78
Avg merge
1d 6h
Merged PRs (30d)
13

Description

Problem:
@OneToMany requires explicit mappedBy even when @ManyToOne
exists on the other side — causing confusion and learning curve.

Proposal:
Add a global property:
jakarta.persistence.detect.bidirectional=true

Behavior:
- false (default) → current behavior preserved
- true → auto scan and link symmetric @OneToMany/@ManyToOne

Benefits:
- Zero breaking changes (opt-in)
- Reduces boilerplate
- Lowers learning curve
- Scan already happens at startup — low implementation

## Prior Art

Other popular ORMs already auto-detect bidirectional relationships:

- **Django ORM** (Python) — automatically creates reverse relation
without any explicit declaration
- **Rails ActiveRecord** (Ruby) — auto-detects inverse_of in most cases
without requiring explicit mapping

Contributor guide

Open the contributing guide

Research direction

The proposal names no files, tests, or entry points. Start by reviewing Jakarta Persistence startup mapping and configuration conventions, then determine how opt-in detection of symmetric @OneToMany/@ManyToOne mappings would be specified and validated. Done requires an agreed property, preserved default behavior, and tests for both disabled and enabled modes.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.