-->
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.  [ 1 post ] 
Author Message
 Post subject: Dynamic assignment of schema and catalog
PostPosted: Fri Jul 15, 2011 5:53 am 
Newbie

Joined: Fri Jul 15, 2011 3:46 am
Posts: 3
As the subject implies, is there some way of doing this? Our databases are set up with one physical database which contains several logical databases, usually one for each product we develop. Some of those logical databases contain shared data which our applications all consume and/or update. The thing is, the logical databases don't have any fixed names, but the name is of course known runtime through configuration files, so we can't rely on hard-coding the schema & catalog in the annotations.

Currently we solve the issue in a somewhat hacky manner by abusing NamingStrategy#tableName(..) and appending catalog & schema there, however that does cause some issues with hibernate when it comes to inverse join columns, secondary tables and other similar annotations. For an example we have a db schema which is something like this

Physical DB
- User-database
- Common-database
- Application specific database

Our mappings would then have
@Table(name="users")

Our naming strategy would then translate the tableName to be: user-db..users (MSSQL) or user-db.users (Oracle)

I know that I can set a default schema, and default catalog, but that only helps as long as the DataSource only accesses one logical database. For some applications that's sufficient, but for the ones which access multiple logical databases we'd wind up having several SessionFactories and DataSources and lose the option of joining between the logical databases.

Ideally I'd like to have the ability to annotate something like this
@Table(name="users", catalog="USER_DB_CATALOG", schema="USER_DB_SCHEMA")
and on startup the mappings would query a Catalog/Schema strategy to translate to the correct values.

I've done some digging in the Hibernate code and documentation and although I can't seem to find any way of solving the issue I do hope I missed something. Closest I've gotten is TableBinder#buildAndFillTable(..) which will retrieve the schema/catalog from the mappings file if it's missing from the annotation. I'm guessing that if it were possible to do I'd find the hook somewhere around there, but sadly I've yet to find any hooks I could plug into.

So, does anyone have any suggestions or solutions for this? I saw a few similar topics both on the board, and other places, but none of them seemed to be similar enough to offer a solution to this issue.

Regard,

Alex


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

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.