-->
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.  [ 7 posts ] 
Author Message
 Post subject: Table.qualify bug in version 3.1+
PostPosted: Wed Feb 01, 2006 3:16 pm 
Beginner
Beginner

Joined: Wed Nov 05, 2003 4:38 pm
Posts: 29
Version: Hibernate 3.1.2 (but I think this applies to anything since 3.1)

Table.qualify has changed and is now incorrect! It does not handle the case for "catalog..tablename" that the old version does. Instead it outputs "catalog.tablename" which is not right (at least on SQL Server 2000).

Old version:
Code:
public static String qualify(String catalog, String schema, String table, char separator) {
    StringBuffer qualifiedName = new StringBuffer();
    if ( catalog != null ) {
        qualifiedName.append( catalog );
        qualifiedName.append( separator );
        qualifiedName.append( schema != null ? schema : "" );
        qualifiedName.append( separator );
    }
    else if ( schema != null ) {
        qualifiedName.append( schema );
        qualifiedName.append( separator );
    }
    qualifiedName.append( table );
    eturn qualifiedName.toString();
}


New version:
Code:
public static String qualify(String catalog, String schema, String table) {
    StringBuffer qualifiedName = new StringBuffer();
    if ( catalog != null ) {
        qualifiedName.append( catalog ).append( '.' );
    }
    if ( schema != null ) {
        qualifiedName.append( schema ).append( '.' );
    }
    return qualifiedName.append( table ).toString();
}


As a side note to this, version 3.0 has a problem with the using a multicolumn usertype in the ORDER BY clause of HQL. It outputs:

ORDER BY (usertypeA_column1, usertypeA_column2)

In SQL Server 2000 the '(' and ')' are not allowed in an ORDER BY clause. I'm not sure if version 3.1+ fixes this yet as I uncovered the above Table.qualify bug first.


Last edited by jkolb on Thu Feb 02, 2006 10:04 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Here is some code to fix this bug.
PostPosted: Wed Feb 01, 2006 6:04 pm 
Beginner
Beginner

Joined: Wed Nov 05, 2003 4:38 pm
Posts: 29
Here is the simplest code that fixes this bug.

Code:
   public static String qualify(String catalog, String schema, String table) {
      StringBuffer qualifiedName = new StringBuffer();
      if ( catalog != null ) {
         qualifiedName.append( catalog ).append( '.' );
      }
      if ( schema != null ) {
         qualifiedName.append( schema ).append( '.' );
      }
      if ( catalog != null && schema == null ) {
         qualifiedName.append( '.' );
      }
      return qualifiedName.append( table ).toString();
   }


Also after fixing this I've determined that the ORDER BY problem that was in 3.0 is fixed in 3.1+.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 06, 2006 5:31 pm 
Beginner
Beginner

Joined: Wed Nov 05, 2003 4:38 pm
Posts: 29
Can someone check that this isn't just a dialect problem? I'm currently running off of a self compiled version of Hibernate with the change in the previous post since I'm using cross catalog mappings a lot, and this change from the 3.0 version pretty much broke all my prior work. The DB is SQL Server 2000.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 3:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
what does catalog..tablename mean for a sql server ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 2:28 pm 
Beginner
Beginner

Joined: Wed Nov 05, 2003 4:38 pm
Posts: 29
In SQL Server catalog is the database name, I believe that schema ends up being the owner of the object, then table is still the table (or other object).

So: database.owner.object or database..object when you don't care to specify the owner.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 3:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
put it in jira with a usecase/argument that shows .. makes sense.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 5:28 pm 
Beginner
Beginner

Joined: Wed Nov 05, 2003 4:38 pm
Posts: 29
http://opensource2.atlassian.com/projects/hibernate/browse/HHH-1476

Does this qualify as a good usecase/argument?


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