Reputation: 1023
I'm trying to understand how to best generate and synchronize domain model POJO's from my database using Hibernate. Right now the process I managed to build is the following:
But this has a lot of problems:
Is it possible to "tell" the generator to map the common table fields to the same classe (createdBy, ModifiedBy, ID, etc...) ?
I'm questioning if this approach makes sense at all? Should I be managing my POJO's by hand ? I don't mind that but some help managing the mapping files (.hbm.xml) would help a lot.
Or should I find some way to go "code first", ie. write the POJO's and then generate the schema ? I'm a bit used to the .NET's entity framework and I feel quite lost on what's the "proper" way to build the persistence layer in Java/Hibernate
Thank you
Upvotes: 1
Views: 657
Reputation: 2460
The Telosys Tools code generator is probably the solution for you.
It uses an existing database to generate any kind of source file for each entity (database table), typically POJO, DTO, DAO, web pages, etc... When the database schema change you just have to regenerate.
For more information see the web site : https://sites.google.com/site/telosystools/ and the tutorials : https://sites.google.com/site/telosystutorial/
All the templates are free and customizable, for Hibernate POJO you can use the JPA templates (https://github.com/telosys-tools/persistence-jpa-TT210-R2) and adapt them if necessary
Upvotes: 3