-->
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.  [ 6 posts ] 
Author Message
 Post subject: [Oracle 9i] [Hibernate 3.0] sysdate.
PostPosted: Sun Apr 24, 2005 2:42 am 
Newbie

Joined: Thu Apr 14, 2005 9:02 am
Posts: 7
Hibernate 3.0.
Oracle 9i.

In the config file, both the "Oracle" dialect and the "Oracle 9i" dialect are chosen.


The following Oracle sql statement returns the current date and time of the database server:


Code:
    select sysdate from dual;


Now try to use HQL to get the same result:

Code:
            String hql = "select sysdate() from Category";  // "sysdate()" is correct, but "sysdate" not.
            Query q = session.createQuery(hql);
            List result = q.list();
           
            Date sysdate = (Date) result.get(0);
            System.out.println("sysdate = " + sysdate.toLocaleString());

Output: The time component of the output is always 00:00:00.

Now try to use a SQL query:


Code:
            String sql = "select sysdate from dual";
            SQLQuery sq = session.createSQLQuery(sql);
            Object[] x = (Object[]) sq.uniqueResult();
           
            System.out.println(x.length);

Output: 0.

Please explain those output.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 24, 2005 7:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
JackyC wrote:
[
In the config file, both the "Oracle" dialect and the "Oracle 9i" dialect are chosen.


i hope you meant tried and not chosen as in both dialect chosen at the same time ?

Quote:

Code:
            String hql = "select sysdate() from Category";  // "sysdate()" is correct, but "sysdate" not.
            Query q = session.createQuery(hql);
            List result = q.list();
           
            Date sysdate = (Date) result.get(0);
            System.out.println("sysdate = " + sysdate.toLocaleString());


[size=18]Output: The time component of the output is always 00:00:00.
[/code]

Yes, sysdate() is a HQL function that returns a DATE not a TIMESTAMP.
Use systimestamp() ot get the wanted behavior.

Quote:

Code:
            String sql = "select sysdate from dual";
            SQLQuery sq = session.createSQLQuery(sql);
            Object[] x = (Object[]) sq.uniqueResult();
           
            System.out.println(x.length);

[size=18]Output: 0.


you haven't specfied what the query returns thus hibernate just return one row with zero columns (we should maybe throw an exception here),
so to get what you want do the following:

Query sq = session.createSQLQuery(sql).addScalar("sysdate", Hibernate.TIMESTAMP);

Quote:
Please explain those output.


Please read the manual and check the log output in the future :)

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Ah, sorry!
PostPosted: Sun Apr 24, 2005 4:52 pm 
Newbie

Joined: Thu Apr 14, 2005 9:02 am
Posts: 7
Code:
            String sql = "select sysdate as system_datetime from dual";
            SQLQuery sq = session.createSQLQuery(sql);
            sq.addScalar("system_datetime", Hibernate.TIMESTAMP);

            Timestamp sysdatetime = (Timestamp) sq.uniqueResult();


And, I used both Oracle and Oracle9i dialect at the same time.
I think it can choose one smartly.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 24, 2005 4:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well submit a patch if you want that ,)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Proposed Fix
PostPosted: Thu Mar 20, 2008 4:10 pm 
Newbie

Joined: Thu Mar 20, 2008 4:04 pm
Posts: 1
Location: Rothschild, WI
I proposed a fix for this at http://opensource.atlassian.com/projects/hibernate/browse/HHH-3193.

_________________
Mark A. Ziesemer
http://www.ziesemer.com


Top
 Profile  
 
 Post subject: Re: [Oracle 9i] [Hibernate 3.0] sysdate.
PostPosted: Sat May 08, 2010 9:04 am 
Newbie

Joined: Sat May 08, 2010 9:00 am
Posts: 1
Hi
you can use type as Timestamp
and Statement stmt= session.connection().createStatement();
Resultset rs =stmt.excutequery("select sysdate from dual");
if(rs.next()){
rs.getTimestamp(1);
}
then insert this timestamp it will work.

_________________
sanjay garothaya


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