Generate pure JPA annotated classes from existing annotated classes

Hello, I’m in an existing codebase that contains 500+ JPA annotated entity classes. These classes also contain business logic and other tightly coupled dependencies. I want to extract these classes to another project and start clean with just pure JPA class entities.

I already tried to generate the POJOS from the database schema with hbm2java (maven-plugin), which resulted in about 1300+ generated classes and loses the inheritance hierarchy. This is mainly due to reveng not recognising the Inheritance Strategy of the existing entity classes.

Any idea’s on how to produce pure/clean annotated POJOs with the correct inheritance hierarchy of the existing classes?

I think that you have to make a custom solution yourself,
the best way is to make all entity classes in one jar file and load it in your custom solution at
runtime , then look for the annotations and extract the classes and fields you need.
Look at the following example i used it for just generating select and create sql statements but it
should help you or at least give you an idea,

and for generating source code at runtime, you can use freemarker template engine to make it easy for you