0

Is there a way that an existing pojo generated by hibernate tools must not be overwrite if I run the hibernate tools code generation?

Consider this scenario: Class Employee is already existing, then I created another table Employee_Salary. If I want to create a pojo class using hibernate tools, Employee Class will be overwrite also. This should not be the case, because I already have some modification with the Person class. Hibernate tools must only generate the EmployeeSalary Class instead. I cannot remove Employee table to revenge file since it is related to Employee_Salary table.

Any idea would be appreciated.

Thanks!

Koraktor
  • 41,357
  • 10
  • 69
  • 99
  • 1
    This may sound unhelpful, but you shouldn't ever make changes to classes that are generated by a tool. If you need to add functionality to such a class, put the functionality in a different class entirely and use composition. – Dawood ibn Kareem Mar 20 '14 at 05:52
  • How about, named queries? Usually, it is placed on the class entity right? And I also add some annotations like insertable=false to field. So those are the changes I make to the class generated by hibernate tools. – codexplorer Mar 21 '14 at 00:53
  • It is fairly common to include named queries in an associated entity's mapping file, if that mapping file is used to create or validate the database, rather than being generated _from_ the database. If you are using generated mapping files, then I strongly recommend putting all your named queries into a mapping file by themselves. – Dawood ibn Kareem Mar 21 '14 at 06:33

1 Answers1

0

Is there a way that an existing pojo generated by hibernate tools must not be overwrite if I run the hibernate tools code generation?

It works with table filter.If you add table filter in the hierbate.reveng.xml then this should works.But you should change table filters when ever you are regenerating code based on what classes you need to generate again.This way old classes will not regenerate again.

In your case,add

<table-filter match-name="Employee" exclude="true" />

But it is not good practice to do any changes in tool generated code,it may revert at any time.I think you need to extend generated classes to write custom business logic.

Sunil Kumar
  • 5,477
  • 4
  • 31
  • 38