jakartaee / jakartaee/persistence

Allow @GeneratedValue for non-@Id fields

Open
#113 19 comments 23 reactions 0 assignees View on GitHub
candidate-for-4.1 Priority: Major Type: Bug
Dominant language
Java
Stars
268
Forks
78
Avg merge
1d 6h
Merged PRs (30d)
13

Description

Hello,

My scenario is the following - I have a @MappedSuperclass which defines a field pk (which is generated value with a custom generic generator) but I also have an entity called Order with a property code. I have created a custom generic generator which calculates on the server what the order code must be, but even though I have specified it as this:

```
@Column(name = "code", nullable = false)
@GenericGenerator(name = "uuid", strategy = "uuid2")
@GeneratedValue(generator = "uuid")
private String code;
```

This generator is never called. I checked the javadoc and there explicitly says that the @GeneratedValue is used together with @Id. My proposal is to allow it to be used on columns that are not @Id.

Contributor guide

Open the contributing guide

Research direction

Start with the @GeneratedValue javadoc and the issue's @MappedSuperclass and Order mapping example. Determine the specification and mapping changes needed to invoke a generator for a non-@Id field; done means the proposed behavior is defined and supported without changing the existing @Id contract.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.