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

Embeddable should be allowed as static inner class #329

Closed
lostiniceland opened this issue Sep 10, 2021 · 1 comment
Closed

Embeddable should be allowed as static inner class #329

lostiniceland opened this issue Sep 10, 2021 · 1 comment

Comments

@lostiniceland
Copy link

lostiniceland commented Sep 10, 2021

For embeddables, the current specification says

Embeddable classes must adhere to the requirements specified in Section 2.1 for entities with the exception that embeddable classes are not annotated as Entity. Embeddable classes must be annotated as Embeddable or denoted in the XML descriptor as such.

And section 2.1 says, among other things

The entity class must be a top-level class.

Modelling an embeddable class as a inner class of an entity is sometimes very usefull. For instance, it makes clear where this embeddable belongs. For a top-level class, the naming would need to follow something like MyEntity and MyEntitySomething, whereas using an inner class the embeddable could just be named Something since it is clear where it belongs.

Hibernate actually already supports this, and we are using this approach, but since it is not covered by the spec we are not sure if this is future-proof.

@Entity
public MyEntity {

   ... other stuff omitted

   @Embedded
   private Something something
  
   @Embeddable
   public static class Something {

   }
}

@gavinking
Copy link
Contributor

Note that this request is now part of #380, so this issue could be closed.

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

2 participants