views:

90

answers:

3

Current project recently had a mess of changes to the DB schema. These were largely style cleanups, such as ensuring that all columns followed a consistent naming pattern and were all_in_snake_case .

I believe we got all of the column references in our DB as well as in our Entities, is it possible to have JPA, EclipseLink, or GlassFish do some sort of "verify all" operation to ensure that each entities columns exist and match??

A: 

My two cents:

  • write unit test for each of your entity to test the mapping and the queries in the DAO. That's an asset for the future which is worth it.
  • you can create the database schema out of the mapping or annotation (turn automatic generation of tables on with eclipselink.ddl-generation), and then compare the two database schemas using some database tool (that will depend on your database. Maybe your DBA, if you have one, can help).
ewernli
You're right. I've been putting off adding unit tests, but I need to bite the bullet and do it.
Freiheit
A: 

Specific to the JPA implementation. DataNucleus can certainly verify your schema matches the entities definitions, and I'm sure other implementations can do something similar

DataNucleus
A: 

Just write a JUnit test that will get all mapped attributes of an Entity using java reflection, and then use SQL to get all columns of the table, and compare them, repeat the operation for all your entities or the table.

for example if you are using oracle as a database use the following query to get your table columns:

select column_name 
from user_tab_columns
where table_name = 'YOUR_TABLE';
Omar Al Kababji