-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to change schema for testing?
PostPosted: Mon Apr 02, 2007 9:56 am 
Newbie

Joined: Mon Aug 02, 2004 1:21 pm
Posts: 9
Hello,

In my current project, i need to access tables located in diferent schemas, therefore I specify the schema of each table in the mapping file.

I would like to create a special schema for unit-testing my DAOs. This schema will contain all tables. I wonder if there is a way to tell hibernate to the schema settings on runtime. This way, I could test against the testing schema without modifying the mapping files or having to maintain diferent mapping files for testing.

Has anyone done anything similar?

Thanks.

Camilo Arango.

_________________
Camilo A.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 02, 2007 10:53 am 
Newbie

Joined: Thu Feb 22, 2007 9:49 am
Posts: 9
I just use multiple database instances, but that's a simple measure if you have multiple machines to play with. That way only the .cfg file needs to change to specify the host on which the database resides.

You could potentially do the same but with each database instance running on a different port, if it is supported by your DB (not actually tried this).

The last possibility is to recreate the hbm.xml files from templates during initialisation, and before the first Session is created. If you use a utility class to contain convenience session handling (like HibernateUtil in the example code), create a static initialiser that reads the source .hbm.xml files and replaces some predetermined token, such as $SCHEMA$ with the actual schema for the current config, then write these files wherever hibernate is expecting to find them.

Performance cost wouldn't be too high either as its a one shot mechanism on startup.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.