persistence icon indicating copy to clipboard operation
persistence copied to clipboard

revisit restrictions on entity, embeddable, and primary key classes

Open gavinking opened this issue 1 year ago • 0 comments

Reviewing the spec, I'm wondering whether we should revise some restrictions on user code.

@Entity classes

An entity class must:

  • be toplevel
  • be non-final
  • have a no-arg constructor (public/protected)
  • have properties declared public/protected

But this leads me to wonder why static inner classes are prohibited?

@Embeddable classes

Embeddable classes have the same restrictions as entity classes.

But I would have expected that an embeddable class should be non-abstract.

And I don't see any reason why static inner classes should be prohibited.

Primary key classes

A primary key class must:

  • be public
  • have a no-arg constructor (public)
  • have properties declared public/protected
  • be serializable
  • declare equals/hashCode

Why must a primary key class be public when we don't apply this restriction to embeddables?

Is the requirement for serializability really necessary? (Yes, I remember where this came from, but I don't believe it's relevant anymore.)

Surely a primary key class should always be non-abstract.

gavinking avatar Sep 08 '22 16:09 gavinking