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

Auto generate record ID class if no explicit @IdClass #681

Open
quaff opened this issue Nov 7, 2024 · 3 comments
Open

Auto generate record ID class if no explicit @IdClass #681

quaff opened this issue Nov 7, 2024 · 3 comments

Comments

@quaff
Copy link

quaff commented Nov 7, 2024

Given an entity meets:

  1. using composite primary key
  2. no @IdClass annotated

For example:

   @Entity
   public class Employee {
      @Id String empName;
      @Id Date birthDay;
      ...
   }

It would be convenient if a record class is generated as implicit @IdClass

   public record EmployeeId(String empName, Date birthDay) {}

candidate names of generated record class:

  • EmployeeId
  • EmployeePK
  • EmployeeId_
  • EmployeePK_
  • Employee$Id
  • Employee$PK
@gavinking
Copy link
Contributor

It's an interesting idea.

candidate names of generated record class

I kinda hate those suggestions though :)

My knee-jerk would be an inner class of Book_, something like Book_.Id_ which does not collide with anything currently defined in 5.1.1. But it does have one potential problem in that in Hibernate Processor, IIRC, we have started using the convention X_.Y_ when you have a static inner class annotated @Entity (which is permitted by the spec, but currently not considered in 5.1.1). Right, @cigaly?

@cigaly
Copy link

cigaly commented Nov 8, 2024

@gavinking Actually, what I've done was generating separate class file for each (static) inner class, so that X.Y will produce X_Y_. [But there should be not big problem to make it as inner class X_.Y_]
Why not generate something like Book_.Id [or Book_Id] by simply ommiting underscore at the end, so that distinction will be more clear?

@quaff
Copy link
Author

quaff commented Nov 8, 2024

I'm voting for Book_.Id.

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

No branches or pull requests

3 participants