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 -
public sealed interface MemberMapping<T>
permits FieldMapping, EmbeddedMapping, ToOneMapping {
}
public record ToOneMapping<T>
(Class<C> containerType, String alias,
String name, Class<T> toOneType,
ColumnMapping[] fkColumns,
...) implements MemberMapping<T> {
}
E.g.
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 );
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 -
E.g.