-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: How to check if the schema corresponds to mappings
PostPosted: Tue Apr 05, 2005 3:20 pm 
Newbie

Joined: Tue Oct 26, 2004 4:21 am
Posts: 10
Location: Belgium
Hello,

I read the SchemaExport and SchemaUpdate docs and I wonder:

Is there a simple way to check if the targeted schema is corresponding with the Configuration loaded (Thus, BEFORE launching a create/drop/create schema process)?

Thanks,
Renaud


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 05, 2005 6:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
not at the moment but we would like to add one

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 05, 2005 7:53 pm 
Newbie

Joined: Fri Apr 01, 2005 1:03 am
Posts: 12
A very high level check is look through your hibernate class meta data (after session factory is initialized) and do an HQL query to a select a row off each table in the database. If you have data in every table, this tests Hibernate mapping each table/column name to their java equivalent.

It will catch some simple mistakes like:

1. Columns that have mismatched names between your mappings and DB.
2. Datatypes that don't match up between your mappings and DB.
3. Columns in the DB that have been dropped.
4. Tables that have been renamed.
5. Tables that have been dropped.


Wrap it in a catch block, and you have an error message for each table telling you what doesn't match up right.

After you have successfully checked whether the database is in sync with your application, you can invoke the SchemaExport task programmatically in your code.

Originally, I investigated using JDBC meta-data to evaluate our database structure, but unfortunately, some of the meta-data (foreign keys) was hidden to our DB2 connection so we had to go with the aforementioned approach.

If you can see all the db meta-data, doing an extensive comparison would be the best approach -- though definately more code intensive.

There is a related topic metioned somewhere on the hibernate wiki or docs that does a "from Object" HQL query to load all persistant instances. I suspect it would break on the first error and be a bit of a performance hit on startup (if you have a decent sized database).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.