jakartaee / jakartaee/persistence
add @EmbeddableResult
- Dominant language
- Java
- Stars
- 268
- Forks
- 78
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 13
Description
Section 3.10.16.1 of the spec specifies that embeddable objects returned by native queries are handled by specifying a property path using the `name` member of `@FieldResult`. For example:
```java
@SqlResultSetMapping(name=”CustomerResults”,
entities=@EntityResult(entityClass=Customer.class,
fields={@FieldResult(name="id", column="customer_id"),
@FieldResult(name="address.street", column="customer_street"),
@FieldResult(name="address.city", column="customer_city"),
@FieldResult(name="address.state", column="customer_state"),
@FieldResult(name="status", column="customer_status")}
)
```
This _works_ but somehow I always found it slightly weird, bordering on inelegant, that, given that `@Embeddable` objects are a basic construct in the type system of JPA, there was no corresponding `@EmbeddableResult` annotation.
```java
@SqlResultSetMapping(name=”CustomerResults”,
entities=@EntityResult(entityClass=Customer.class,
fields={@FieldResult(name="id", column="customer_id"),
@FieldResult(name="status", column="customer_status")},
embeddables=@EmbeddableResult(name = address,
fields={@FieldResult(name="street", column="customer_street"),
@FieldResult(name="city", column="customer_city"),
@FieldResult(name="state", column="customer_state")}))
)
```
Is that better? Maybe not. We all hate nested annotations in Java!
But in light of #459, this code example can easily be made typesafe, whereas the first cannot:
```java
@SqlResultSetMapping(name=”CustomerResults”,
entities=@EntityResult(entityClass=Customer.class,
fields={@FieldResult(name=Customer_.ID, column="customer_id"),
@FieldResult(name=Customer_.STATUS, column="customer_status")},
embeddables=@EmbeddableResult(name = address,
fields={@FieldResult(name=Address_.STREET, column="customer_street"),
@FieldResult(name=Address_.CITY, column="customer_city"),
@FieldResult(name=Address_.STATE, column="customer_state")}))
)
```
And this is, in my opinion, sufficient reason to add such an annotation to JPA.
Contributor guide
Research direction
Start with the issue's examples and the referenced JPA specification section 3.10.16.1. The payload names no repository files, tests, or entry points, so the API surface and required compatibility tests must first be identified. Done means agreeing on the annotation design and implementing it with tests covering embeddable results in native-query mappings.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100