-->
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: Specifying the schema programatically
PostPosted: Tue Apr 15, 2008 5:24 pm 
Newbie

Joined: Mon Apr 14, 2008 11:24 am
Posts: 5
Hi,
I am using Oracle database and I have available multiple schemas with identical structure but that are used for different customers or for test purposes.
I only have one user -and therefore a single default schema-.

I manage to work with different schemas by modyfing my Hibernate mappings using the "schema" attribute of the "<class>" elements in the "<hibernate-mapping>" file.
Nevertheless, this implies that I need to change the XML files every time that I need to switch to a different schema.

Is there anyway to specify this programatically?

Below is the segment of one of my files

<hibernate-mapping>
<class name="com.myenterprise.test.hibernate.ormdata.MyClass" table="T_MYTABLE" schema="TEST_SCHEMA">
<id name="campaignId" type="big_decimal">
<column name="THE_ID" precision="22" scale="0" />
<generator class="assigned" />
</id>
...
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 16, 2008 8:58 am 
Newbie

Joined: Tue Oct 09, 2007 3:09 am
Posts: 6
Something like this should help:
Code:
Configuration cfg =
...
Iterator it = cfg.getClassMappings();
while (it.hasNext())
{
  org.hibernate.mapping.PersistentClass cls = (org.hibernate.mapping.PersistentClass)it.next();
  cls.getTable().setSchema(schemaName);
}


Top
 Profile  
 
 Post subject: Specifying the schema programatically
PostPosted: Wed Apr 23, 2008 7:48 am 
Newbie

Joined: Wed Apr 23, 2008 7:18 am
Posts: 1
Location: Russia, SPb
Hello Victor,
Thank you for a proposed solution. It works quite well, but it is slightly incomplete. In your code you are patching tables related to entity tables, but tables related to collection mappings are left untouched.

I am using the following code:

for (Iterator it = cfg.getTableMappings(); it.hasNext();) {
org.hibernate.mapping.Table mappingTable = (org.hibernate.mapping.Table) it.next();
mappingTable.setSchema(schemaName);
}

_________________
Best regards, Alexey


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.