jakartaee / jakartaee/persistence
Allow @GeneratedValue for non-@Id fields
- 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
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