Skip to content

add mappedById to @ManyToOne and @OneToOne#973

Open
gavinking wants to merge 3 commits intojakartaee:mainfrom
gavinking:#527
Open

add mappedById to @ManyToOne and @OneToOne#973
gavinking wants to merge 3 commits intojakartaee:mainfrom
gavinking:#527

Conversation

@gavinking
Copy link
Copy Markdown
Member

For consideration. Competes with #958.

see #527

@gavinking
Copy link
Copy Markdown
Member Author

Thoughts, @sebersole? @njr-11?

Comment thread api/src/main/java/jakarta/persistence/OneToOne.java Outdated
Co-authored-by: Nathan Rauh <[email protected]>
@gavinking gavinking mentioned this pull request Apr 15, 2026
@gavinking gavinking marked this pull request as ready for review April 15, 2026 09:41
@gavinking gavinking added the candidate-for-4 Good candidate for JPA 4 label Apr 15, 2026
@gavinking gavinking linked an issue Apr 15, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Contributor

@sebersole sebersole left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it. Left a comment about changes to the javadoc for mappedBy for consideration, but otherwise +1

/**
* The field that owns the relationship. Required unless
* the relationship is unidirectional.
/**
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mappedBy serves 2 purposes and I think it makes sense to discuss both of them here. This is a great discussion about the runtime implication in terms of ownership.

But it also defines semantics of the foreign-key - look "there" for it. And in the case of one-to-one actually defines the key side versus the target side of the foreign-key. That's perhaps obvious to us by the term "inverse" but is that generally understood? Not sure.

Same comment for mapedBy on @OneToMany and @OneToOne.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, OK.

@gavinking
Copy link
Copy Markdown
Member Author

@sebersole and I discussed this today, and decided to put it on ice for now. We might reconsider it for 4.1 or whatever.

@gavinking gavinking added candidate-for-4.1 and removed candidate-for-4 Good candidate for JPA 4 PRIORITY labels Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add mappedBy to @ManyToOne and @OneToOne

3 participants