Search code examples
javahibernatehibernate-validator

Hibernate Validation - Maintenance issues with auto generated POJOs


I have reverse engineered(auto generated) the model and DAO classes from database using Hibernate-Tools in eclipse. In those auto generated model classes, I have manually added Hibernate validation annotations at a lot of places. One example is as follows:

  @Length(min = 5, message = "*Your password must have at least 5 characters")
  @NotEmpty(message = "*Please provide your password")
  @Transient
  private String password;

Now my question is that database tables can be modified frequently, to incorporate new features, and changes. And after changes, model classes will have to be auto generated again, in which case I'll have to write validation annotations again. And that will happen in case of every change to existing tables. Is there any way so that hibernate validations(or spring validations) can be separated from model classes. So that one does not have to rewrite them after auto-generating code every time.


Solution

  • You typically only reverse engineer your models once when you have the schema and want to generate your models directly.

    For incremental changes you make, most developers typically just modify the schema and models manually or make the necessary changes to their entity models and allow Hibernate's schema tooling to alter the underlying database schema as-needed.

    What you're asking is not something that is currently supported.