aspose file tools*
The moose likes Object Relational Mapping and the fly likes How to keep Hibernate from exporting a schema if one already exists? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to keep Hibernate from exporting a schema if one already exists?" Watch "How to keep Hibernate from exporting a schema if one already exists?" New topic
Author

How to keep Hibernate from exporting a schema if one already exists?

James Adams
Ranch Hand

Joined: Sep 12, 2003
Posts: 188
I sometimes run DbUnit tests of my Spring application's DAOs using an in-memory HSQL database, and other times using an Oracle database. It's necessary to allow Hibernate to build the schema for the HSQL database (since one doesn't already exist), but when I run the DbUnit tests against the Oracle database I do not want the schema to be modified. Currently I am commenting out the hibernate.hbm2ddl.auto property of my Hibernate SessionFactory bean when I run DbUnit tests using Oracle as my DataSource, but I expect that there's a better way to go about this. Ideally what I'd like to use is a property value for hibernate.hbm2ddl.auto which tells the schema exporter to only update/create a schema if one doesn't already exist, but I don't see such a value available for this property.

Can anyone give me suggestions on how to better approach this problem? Thanks in advance for any responses.


--James
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

I think you just did

"hibernate.hbm2ddl.auto" value to "update"

From the Hibernate docs.

" hibernate.hbm2ddl.auto=update Creates the database schema on deploy if it doesn't exist. Alters it if it has changed. Useful for when you want to generate database schema from entity beans"


Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
James Adams
Ranch Hand

Joined: Sep 12, 2003
Posts: 188
Yes I use update when I want the HSQL schema created, but if one already exists in the Oracle database then I don't want it modified at all, even if it's out of sync with the Hibernate mappings. What I want is a value for this Hibernate property other than update, which tells Hibernate to only create/update the schema if one doesn't exist, otherwise do nothing (i.e. do not modify an existing schema).

Maybe what I need to do is to not rely on the Hibernate automatic schema creation/update and instead somehow perform this step programmatically for my DbUnit tests only when they are using the in-memory HSQL database, which is the only time it's really needed.


--James
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to keep Hibernate from exporting a schema if one already exists?
 
Similar Threads
hibernate.hbm2ddl.auto value to do both the operations i.e create/update on database schema?
Dao integration unit test issue (rollback or temporary database)
database schema definition outside of hbm files?
Which hibernate property is causing the existing data to be deleted?
Programatic Schema Export with Hibernate and EJB3