How to use enums with JPA

前端 未结 11 1073
梦如初夏
梦如初夏 2020-12-03 02:47

I have an existing database of a film rental system. Each film has a has a rating attribute. In SQL they used a constraint to limit the allowed values of this attribute.

11条回答
  •  情深已故
    2020-12-03 03:02

    The problem is, I think, that JPA was never incepted with the idea in mind that we could have a complex preexisting Schema already in place.

    I think there are two main shortcomings resulting from this, specific to Enum:

    1. The limitation of using name() and ordinal(). Why not just mark a getter with @Id, the way we do with @Entity?
    2. Enum's have usually representation in the database to allow association with all sorts of metadata, including a proper name, a descriptive name, maybe something with localization etc. We need the easy of use of an Enum combined with the flexibility of an Entity.

    Help my cause and vote on JPA_SPEC-47

提交回复
热议问题