views:

68

answers:

1

Is there a way to automatically create javax.persistence.Entity classes from an existing database (or from the SQL statements that created them)?

I am just reading through the persistence part of The Java EE 5 Tutorial and creating all these annotations by hand seems rather wasteful considering that all (or most) of the necessary knowledge is already encoded in the database or even explicitly given in the form of SQL statements.

+3  A: 

There are several attemps to reverse engineer databases to create entity classes, one of the first google results show this blog, but you can find quite a lot information. Also if you are going to use hibernate, check for ddl2hbm tools, what basically is the very same idea.

pedromarce
Excellent, your link has exactly what I was looking for. Creating a "JPA Project" in Eclipse and right-click on it gives you "JPA Tools" which includes "Generates Tables from Entities" and "Generate Entities from Tables". Thank you!
dareios