-->
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: Using Informix TODAY built-in function in where clause
PostPosted: Wed Jun 16, 2010 4:34 pm 
Newbie

Joined: Fri Jun 04, 2010 10:54 am
Posts: 10
Location: USA
I'm using Hibernate 3.3.2GA against an Informix 11.5 database.
Records are begin- and end-dated in this database, so I want to define where clauses for a few classes to limit the retrieval to only active records, which would look like this:
Code:
<class name="ClassName" table="table_name" schema="informix"
           where="begin_dt &lt;= TODAY AND (end_dt IS NULL OR end_dt &gt; TODAY)">
...

This makes use of the Informix built-in function TODAY which returns the current date (it also has CURRENT which returns current datetime). However, Hibernate is considering this to be a column and is therefore prepending its table prefix to it to treat it like another column of this table. This results in an error:
Column (today) not found in any table in the query (or SLV is undefined)

Can someone tell me if...
1.) there's some generic Hibernate way of referencing the database current date, or
2.) there's someplace I can tweak the Hibernate code so that I can prevent it from prepending the table prefix to the TODAY or CURRENT Informix functions?

Thanks!
-Jeff


Top
 Profile  
 
 Post subject: Re: Using Informix TODAY built-in function in where clause
PostPosted: Wed Jun 16, 2010 6:24 pm 
Newbie

Joined: Fri Jun 04, 2010 10:54 am
Posts: 10
Location: USA
Not to distract from the original question here, but in looking into this I've also discovered that the where clause defined in the mapping definition for the class is not always used - it's used when loading the class itself but not when loading the class as a part of an association with another class. That doesn't seem right to me. It should always apply. And using a filter does not seem like a good option, as that involves the complexity of making sure it's enabled plus it means more rows than are desired will be returned from the database and then just filtered from the returned set.

Is my understanding of this correct? If so, is there any way that I'm not aware of to enable the where clause to be used in all cases when loading a class?

Thanks,
-Jeff
(Debated starting a new thread, but since this is on the topic of the where clause already, I figured I'd tack it on here.)


Top
 Profile  
 
 Post subject: Re: Using Informix TODAY built-in function in where clause
PostPosted: Tue Jun 29, 2010 1:01 pm 
Newbie

Joined: Fri Jun 04, 2010 10:54 am
Posts: 10
Location: USA
Was able to get this working by creating my own custom dialect class which registers today/current as keywords.
Code:
import org.hibernate.dialect.InformixDialect;

public class InformixCustomDialect extends InformixDialect {

   public InformixCustomDialect() {
      super();
      registerKeyword("today");
      registerKeyword("current");
   }

}
Then, of course, I had to adjust my hibernate.dialect property to use this custom dialect class instead.

* One thing that was tripping me up for a while on this was that apparently Hibernate is very picky about case, so keywords must be specified/registered as all lowercase. A very helpful coworker pointed me to this bug. So I had to change TODAY to today in my where clause in addition to registering the keyword.

Still think the inconsistent use of the where clause is incorrect, but that's somewhat of a separate issue. Curious to hear any input on that though.

Hope this helps someone...
-Jeff


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.