jakartaee / jakartaee/persistence

add a prefixing mechanism for @Embedded

Open
#23 19 comments 22 reactions 0 assignees View on GitHub
Priority: Minor RFE Type: New Feature
Dominant language
Java
Stars
267
Forks
78
Avg merge
1d 6h
Merged PRs (30d)
13

Description

Currently working with @Embedded is not really user friendly. If you have multiple Embedded fields in an Entity, then you need to excessively use @AttributeOverrides to use them. This is not only a real nightmare to write down, but also an absolute pain when it comes to refactoring or if you just add or remove a column.

It gets even worse if you have a nested @Embedded structure!

The solution could be to allow specifying a 'prefix' as JDO knows it for years.

Let's first look at the Embeddable

```
@Embeddable
public class Address {
private String name1;
private String name2;
private String street1;
private String street2;
private String zip;
private String tel;
// ... + getters and setters }
```

(please let's not argue about whether this should better be stored 1:n but just take it as sample for now)

Then we look at a possible solution with the prefix:

```
@Entity
public class Customer {
...

@Embedded(prefix="S_")
private Address serviceAddress;

@Embedded(prefix="B_")
private Address billingAddress;

@Embedded(prefix="P_")
private Address physicalAddress;
}
```

You all know what pain it is to do the same in JPA right now ...

Contributor guide

Open the contributing guide

Research direction

The issue names @Embedded, @Embeddable, and @AttributeOverrides but provides no repository files or tests. Start by locating their existing specification and implementation entry points, then define prefix behavior for repeated and nested embeddables. Done means the proposed prefix removes the need for the shown overrides and is covered for both examples.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.