Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
James Adams
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
James Adams
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic