Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fallback id generator #511

Closed
gavinking opened this issue Aug 28, 2023 · 4 comments · Fixed by #514
Closed

fallback id generator #511

gavinking opened this issue Aug 28, 2023 · 4 comments · Fixed by #514

Comments

@gavinking
Copy link
Contributor

gavinking commented Aug 28, 2023

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
Copy link
Contributor

lukasj commented Aug 28, 2023

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

  • maven 3.6.0-3.6.2 was somehow ignoring package-info files as such causing issues running xjc/jaxb etc (I wasn't directly involved in debugging this but noticed problems in few projects)
  • maven compiler version 3.10.0 changed the way it treats package-infos (partially described in MCOMPILER-205) and that has impact on multi-release builds (package-info files are not in certain configurations by default recompiled under the other/lower release version)

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
Copy link
Contributor Author

@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
Copy link
Contributor Author

gavinking commented Aug 29, 2023

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:

  • if name is specified, the annotation defines a single (global) generator as usual, but
  • if name is defaulted, the annotation is a template which defines a generator of each entity which needs one (and its name is the name of the entity, consistently to what we defined earlier).

gavinking added a commit to gavinking/jpa-api that referenced this issue Aug 29, 2023
gavinking added a commit to gavinking/jpa-api that referenced this issue Aug 29, 2023
gavinking added a commit to gavinking/jpa-api that referenced this issue Aug 29, 2023
@gavinking gavinking linked a pull request Aug 29, 2023 that will close this issue
@gavinking
Copy link
Contributor Author

gavinking commented Aug 29, 2023

See 6f6e593.

gavinking added a commit to gavinking/jpa-api that referenced this issue Aug 29, 2023
gavinking added a commit to gavinking/jpa-api that referenced this issue Sep 4, 2023
lukasj pushed a commit that referenced this issue Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants