Reputation: 889
I have java classes with @Table and @Column mapping annotations. I'm currently using hibernate as the ORM. I would like to use some kind of a compile\build time step to check all of the names (and preferably types too) against a live test database, preferably using maven. Ideally the build will fail if there is a column name or table name in the annotations that is not defined in a particular table or database on the server.
Is there a way to pull this off?
Upvotes: 1
Views: 532
Reputation: 1912
Create a JUnit test that will do
Persistence.createEntityManagerFactory("YOUR_TEST_PU");
In your test persistence.xml file add the line below:
<property name="hibernate.hbm2ddl.auto" value="validate"/>
Like this the JPA will validate your schema with your code. If there is an error the test will break and your build too.
Upvotes: 3