jakartaee / persistence

https://jakartaee.github.io/persistence/
Other
203 stars 59 forks source link

fallback id generator #511

Closed gavinking closed 1 year ago

gavinking commented 1 year ago

It would be very convenient to be able to specify a "fallback" id generator to use when @GeneratedValue has no generator member, and the entity does not explicitly declare any @TableGenerator or @SequenceGenerator. This fallback could even be per-GenerationType.

One way would be via a property setting, so that, for example, you could set:

jakarta.persistence.generator.AUTO = myDefaultSequenceGenerator
jakarta.persistence.generator.SEQUENCE = myDefaultSequenceGenerator
jakarta.persistence.generator.TABLE = myDefaultTableGenerator

But actually the most natural solution would be to let you declare a @TableGenerator or @SequenceGenerator with no name at the package level. And then that generator would be used as the fallback for the whole package.

That's a great solution, but I believe @lukasj mentioned he has some problems with us using package-level annotations.

lukasj commented 1 year ago

those "problems" are mostly relate to the build tool(s) being used:

OTOH I do not think we should be feeling blocked by issues in particular build tools - there are other tools having no problems with this and since Java language has package-info we should use it if it makes sense to us

gavinking commented 1 year ago

@lukasj OK, then in that case I would consider this one for 3.2, since it ties in with work we already did.

Actually, a package-level annotation would also be a super nice solution to #409, IMO.

gavinking commented 1 year ago

the most natural solution would be to let you declare a @TableGenerator or @SequenceGenerator with no name at the package level. And then that generator would be used as the fallback for the whole package.

If we allowed @TableGenerator and @SequenceGenerator the package level, the semantics would be:

gavinking commented 1 year ago

See https://github.com/jakartaee/persistence/pull/514/commits/6f6e593d00bcd82f0cb3320759774389914f0c52.