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

"entity local" @SequenceGenerator/@TableGenerator #406

Closed
gavinking opened this issue May 8, 2023 · 0 comments · Fixed by #416
Closed

"entity local" @SequenceGenerator/@TableGenerator #406

gavinking opened this issue May 8, 2023 · 0 comments · Fixed by #416
Projects

Comments

@gavinking
Copy link
Contributor

The spec says that a @SequenceGenerator and @TableGenerator annotation defines a named generator whose name is global to the whole persistence unit.

But a very common idiom is to specify one of these annotations directly on the @Id attribute or @Entity class, and in that case it makes much more sense for the generator to be seen as local to the entity.

I'm not completely sure how we should "fix" this, but one idea would be to make the name annotation member optional, and treat @SequenceGenerator and @TableGenerator annotations without a name as local to the entity, and used by default. For example:

@Entity 
class Book {
    @Id @GeneratedValue
    @SequenceGenerator(sequenceName="seq_book", allocationSize=10)
    Long id;
}

Or:

@SequenceGenerator(sequenceName="seq_book", allocationSize=10)
@Entity 
class Book {
    @Id @GeneratedValue
    Long id;
}

would now be accepted, and the @SequenceGenerator would be visible only to the Book entity, and implicitly used as the generator for that entity.

This would avoid the need for nastiness like:

@Entity 
class Book {
    @Id @GeneratedValue(strategy=SEQUENCE, generator="bookSeq")
    @SequenceGenerator(name="bookSeq", sequenceName="seq_book", allocationSize=10)
    Long id;
}

and is more typesafe to boot (one less stringly-typed name).

gavinking added a commit to gavinking/jpa-api that referenced this issue May 25, 2023
gavinking added a commit to gavinking/jpa-api that referenced this issue May 25, 2023
gavinking added a commit to gavinking/jpa-api that referenced this issue May 25, 2023
gavinking added a commit to gavinking/jpa-api that referenced this issue May 25, 2023
@lukasj lukasj linked a pull request Aug 4, 2023 that will close this issue
@lukasj lukasj added this to To do in 3.2.0 via automation Aug 4, 2023
@lukasj lukasj moved this from To do to In progress in 3.2.0 Aug 4, 2023
gavinking added a commit to gavinking/jpa-api that referenced this issue Aug 7, 2023
3.2.0 automation moved this from In progress to Done Aug 8, 2023
lukasj added a commit that referenced this issue Aug 8, 2023
See #406

Co-authored-by: Lukas Jungmann <lukas.jungmann@oracle.com>
gavinking added a commit to gavinking/jpa-api that referenced this issue Aug 29, 2023
…n spec

I missed this ... it was only defined in the Javadoc

see jakartaee#406
gavinking added a commit to gavinking/jpa-api that referenced this issue Aug 29, 2023
…n spec

I missed this ... it was only defined in the Javadoc

see jakartaee#406
gavinking added a commit to gavinking/jpa-api that referenced this issue Sep 4, 2023
…n spec

I missed this ... it was only defined in the Javadoc

see jakartaee#406
lukasj pushed a commit that referenced this issue Sep 4, 2023
…n spec

I missed this ... it was only defined in the Javadoc

see #406
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
3.2.0
Done
Development

Successfully merging a pull request may close this issue.

1 participant