jakartaee / jakartaee/persistence
New MemberMapping
- Dominant language
- Java
- Stars
- 267
- Forks
- 78
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 13
Description
I know @gavinking is not super keen on unsealing `ResultSetMapping` - #887.
As mentioned there, there are a few things in Hibernate's legacy dynamic ResultSet mapping API for native SQL that we cannot express in `ResultSetMapping`. The biggest one is the notion of mapping a join fetch (to-one).
As an alternative to #887, how about adding the ability to map fetched to-one associations -
```java
public sealed interface MemberMapping
permits FieldMapping, EmbeddedMapping, ToOneMapping {
}
public record ToOneMapping
(Class containerType, String alias,
String name, Class toOneType,
ColumnMapping[] fkColumns,
...) implements MemberMapping {
}
```
E.g.
```java
var sqlString = """
select ...,
b.title,
p.name,
b.publisher_fk,
b.id,
p.id
from books b
join publishers p on b.publisher_fk = p.id
""";
var publisher = toOne(Book_.publisher,
"p",
members(
field("name", ... ),
...
)
);
var bookMapping = entity(Book.class,
"b",
members(
field("title" ),
publisher,
...
)
);
em.createNativeQuery( sqlString, bookMapping );
```
Contributor guide
Research direction
Start by reading the existing ResultSetMapping API and the discussion in #887, then compare the legacy dynamic ResultSet mapping behavior described here. Done means agreeing on and implementing a supported MemberMapping design that can express fetched to-one associations for native SQL queries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design, database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100