OpenJPA
  1. OpenJPA
  2. OPENJPA-1963

bean-validation constraints should be used for generating ddl schemas

    Details

    • Type: New Feature New Feature
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.1.0
    • Fix Version/s: None
    • Component/s: validation
    • Labels:
      None

      Description

      the bean-validation spec. contains:
      >Persistence Providers are encouraged to make use of Bean Validation constraint metadata when generating DDL schemas.
      other jpa2 implementations already support it. it's a really useful feature and might be a blocker for users who would like to use openjpa2.

        Activity

        Hide
        Rick Curtis added a comment -

        > other jpa2 implementations already support it.
        Which providers already provide support?

        Thanks,
        Rick

        Show
        Rick Curtis added a comment - > other jpa2 implementations already support it. Which providers already provide support? Thanks, Rick
        Hide
        Gerhard Petracek added a comment -

        see hibernate annotations

        regards,
        gerhard

        Show
        Gerhard Petracek added a comment - see hibernate annotations regards, gerhard
        Hide
        Rick Curtis added a comment -

        http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/additionalmodules.html#d0e20757
        23.1.4. Database schema

        Hibernate uses Bean Validation constraints to generate an accurate database schema:

        • @NotNull leads to a not null column (unless it conflicts with components or table inheritance)
        • @Size.max leads to a varchar(max) definition for Strings
        • @Min, @Max lead to column checks (like value <= max)
        • @Digits leads to the definition of precision and scale (ever wondered which is which? It's easy now with @Digits )

        These constraints can be declared directly on the entity properties or indirectly by using constraint composition.

        Show
        Rick Curtis added a comment - http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/additionalmodules.html#d0e20757 23.1.4. Database schema Hibernate uses Bean Validation constraints to generate an accurate database schema: @NotNull leads to a not null column (unless it conflicts with components or table inheritance) @Size.max leads to a varchar(max) definition for Strings @Min, @Max lead to column checks (like value <= max) @Digits leads to the definition of precision and scale (ever wondered which is which? It's easy now with @Digits ) These constraints can be declared directly on the entity properties or indirectly by using constraint composition.
        Hide
        Jeremy Bauer added a comment -

        This feature was included under "Ideas explored and not standardized" in an appendix of the JSR-303/Bean Validation specification and simply wasn't ready for prime time at the time the spec was published. OpenJPA could have chosen to implement this feature, but at the risk of implementing a feature that most likely will be updated and possibly cause backward compatibility issues in a future version. It was decided not to implement the feature for that reason. My guess is that we'll see this feature become standardized (non-optional) and expanded upon in the next revisions of the Bean Validation and JPA specifications.

        Side note - scanning for these annotations in OpenJPA would be fairly trivial. Processing constraints defined in XML will be more difficult. OpenJPA would need to either do all the same annotation + constraint XML processing as the Bean Validation provider or tie into whatever constraint metadata is supplied by the validation API to determine which constraints need to applied as mapping information. If we considered adding this feature to a future version of OpenJPA 2.x.x (based on JPA 2.0 and BV 1.0), my preference would be to require users to specifically enable it via an option on the configuration and mapping tool.

        Show
        Jeremy Bauer added a comment - This feature was included under "Ideas explored and not standardized" in an appendix of the JSR-303/Bean Validation specification and simply wasn't ready for prime time at the time the spec was published. OpenJPA could have chosen to implement this feature, but at the risk of implementing a feature that most likely will be updated and possibly cause backward compatibility issues in a future version. It was decided not to implement the feature for that reason. My guess is that we'll see this feature become standardized (non-optional) and expanded upon in the next revisions of the Bean Validation and JPA specifications. Side note - scanning for these annotations in OpenJPA would be fairly trivial. Processing constraints defined in XML will be more difficult. OpenJPA would need to either do all the same annotation + constraint XML processing as the Bean Validation provider or tie into whatever constraint metadata is supplied by the validation API to determine which constraints need to applied as mapping information. If we considered adding this feature to a future version of OpenJPA 2.x.x (based on JPA 2.0 and BV 1.0), my preference would be to require users to specifically enable it via an option on the configuration and mapping tool.

          People

          • Assignee:
            Unassigned
            Reporter:
            Gerhard Petracek
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:

              Development