-->
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: Schema Change Fix
PostPosted: Mon Feb 13, 2006 2:57 pm 
Newbie

Joined: Mon Oct 24, 2005 6:34 pm
Posts: 14
Location: Guadalajara, Jalisco. México.
Hi, I believe I found a minor bug on hibernate, my code changes schemas at runtime by deploying the same jar to different PersistenceUnits, each one having its own different schema, schemas werent being handled properly so I found the following in hibernate code (org.hibernate.cfg.Configuration.java):

Code:
   String defaultCatalog = properties.getProperty( Environment.DEFAULT_CATALOG );
   String defaultSchema = properties.getProperty( Environment.DEFAULT_SCHEMA );
   // ...
   TableMetadata tableInfo = databaseMetadata.getTableMetadata(
      table.getName(),
      //table.getSchema(),  <-- this line fails, at least with my DB (Using Postrgres)
      defaultSchema, //     <-- So I changed for this one wich changes schema properly
      table.getCatalog() // <-- Don't know if catalog should be fetched from environment too
   );
   // ...


inside functions

Code:
public String[] generateSchemaUpdateScript(Dialect dialect, DatabaseMetadata databaseMetadata) throws HibernateException { ... }
      and
public void validateSchema(Dialect dialect, DatabaseMetadata databaseMetadata) throws HibernateException { ... }


Now schemas are handled properly, but changing that lead to another error, IndexOutOfBoundsException (org.hibernate.tool.hbm2ddl.DatabaseMetadata.java) :

Code:
public boolean isTable(Object key) throws HibernateException {
   if(key instanceof String) {
      if ( getTableMetadata( (String) key, null, null ) != null ) {
         return true;
      } else {
         String[] strings = StringHelper.split(".", (String) key);
         if(strings.length==3) {
            return getTableMetadata(strings[2], strings[1], strings[2]) != null;
         } else if (strings.length==2) {
            // This is the code I changed, IndexOutOfBounds was here
            return getTableMetadata(strings[1], strings[0], null) != null;
            
            // This was the original code
            // return getTableMetadata(strings[2], strings[1], null) != null;
         }
      }
   }
   return false;
}


now beans compile and deploy succesfully, and persistence units are changed to others on different schemas at runtime, DDL are created propery and (so far) everything works fine (apparently).


If this is really a bug, don't who to tell, nor how.


----------------------------------------
jBoss 4.0.3SP1
Hibernate 3.1.2 (Compiled with custom fixes)
PostgreSQL 8
Debian/XeonDual


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 16, 2006 12:49 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i think some of this is fixed already, so try it with latest cvs and if it still fails then submit a bug our jira

_________________
Max
Don't forget to rate


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.