-->
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.  [ 8 posts ] 
Author Message
 Post subject: nullif in OracleDialect errors out in Oracle 8
PostPosted: Tue Jul 19, 2005 5:56 pm 
Newbie

Joined: Tue Jul 19, 2005 5:44 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.05

Name and version of the database you are using: Oracle 8

I have a problem with OracleDialect - I picked OracleDialect and not Oracle9Dialect as it's for "any version". I assume this means 8, since Oracle9Dialect is for 9 and 10.

I have a base class with three union-subclass entries. If I do a select for the base class (which checks subclasses too) it generates an SQL union. To do this, it has to fill in the missing columns for the smaller sized tables. It does this by adding a bunch of nullif(0,0) or nullif('x','x') entries into the select for those tables.

This is coming from

public String getSelectClauseNullString(int sqlType) {
String literal;
switch(sqlType) {
case Types.VARCHAR:
literal = "'x'";
break;
case Types.CHAR:
literal = "'x'";
break;
case Types.DATE:
literal = "'2000-1-1'";
break;
case Types.TIMESTAMP:
literal = "'2000-1-1 00:00:00'";
case Types.TIME:
literal = "'00:00:00'";
default:
literal = "0";
}
return "nullif(" + literal + ',' + literal + ')';
}

but nullif doesn't work, Oracle 8 just bombs out as it's an "invalid column name". In particular, in a SQL session:

select id from table -- works
select id, nullif(0,0) from table -- errors out

Is there any easy way for me to get rid of the nullifs? is there an alternate OracleDialect perhaps? or do I have to make a custom dialect based on it. Creative suggestions welcome, I am only looking for a pragmatic solution. Upgrading Oracle is not a viable one for me, at least not just to work around this hibernate quirk.

Thanks in advance for all advice,
Oliver


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 6:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Well, you'll have to figure out how to get a "typed" null in oracle8. I don't know how myself. Then customizing the dialect will be easy.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 7:47 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
gavin wrote:
Well, you'll have to figure out how to get a "typed" null in oracle8. I don't know how myself. Then customizing the dialect will be easy.


You mean the following?
Code:
SELECT NVL(col, 'xyz') FROM table


Maybe, you'll also need these ones to get a type-safe null value.
Code:
TO_CHAR(NULL)
TO_NUMBER(NULL)
TO_DATE(NULL)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 7:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Nope, it can't use a column reference in it.

How about you just create and test a patch for the Dialect.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 8:17 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
NULLIF(..) is definitely not available prior to Oracle 9i.

Sorry, I don't have an Oracle database here to test, but what about the following:

Code:
public String getSelectClauseNullString(int sqlType) {
   String nullConversion;
   switch(sqlType) {
      case Types.VARCHAR:
         nullConversion = "TO_CHAR(NULL)";
         break;
      case Types.CHAR:
         nullConversion = "TO_CHAR(NULL)";
         break;
      case Types.DATE:
         nullConversion = "TO_DATE(NULL)";
         break;
      case Types.TIMESTAMP:
         nullConversion = "TO_DATE(NULL)";
      case Types.TIME:
         nullConversion = "TO_DATE(NULL)";
      default:
         nullConversion = "TO_NUMBER(NULL)";
   }
   return nullConversion;
}


This will return type-safe null values as it does with NULLIF(..).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 8:30 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Sorry, I missed some breaks using the current method.

Code:
public String getSelectClauseNullString(int sqlType) {
   String nullConversion;
   switch(sqlType) {
      case Types.VARCHAR:
         nullConversion = "TO_CHAR(NULL)";
         break;
      case Types.CHAR:
         nullConversion = "TO_CHAR(NULL)";
         break;
      case Types.DATE:
         nullConversion = "TO_DATE(NULL)";
         break;
      case Types.TIMESTAMP:
         nullConversion = "TO_DATE(NULL)";
         break;
      case Types.TIME:
         nullConversion = "TO_DATE(NULL)";
         break;
      default:
         nullConversion = "TO_NUMBER(NULL)";
         break;
   }
   return nullConversion;
}


By the way, aren't there also missing these breaks in the current method?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 20, 2005 1:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Thanks, committed. Apparently that code was never tested on ora8 :-\


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 20, 2005 9:40 am 
Newbie

Joined: Tue Jul 19, 2005 5:44 pm
Posts: 2
wow, thanks guys :)

I'm going ahead and using the TO_X(NULL) in a custom dialect for now.

-Oly


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