How to use enums with JPA

前端 未结 11 1090
梦如初夏
梦如初夏 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:01

    Resolved!!! Where I found the answer: http://programming.itags.org/development-tools/65254/

    Briefly, the convertion looks for the name of enum, not the value of attribute 'rating'. In your case: If you have in the db values "NC-17", you need to have in your enum:

    enum Rating {
    (...)
    NC-17 ( "NC-17" );
    (...)

提交回复
热议问题