views:

179

answers:

4

Hi folks,

I have a Date type column in Oracle DB and it contains date and time for sure. But when I'm trying to get data in java application it will return date with bunch of zeros instead of real time. In code it'll be like:

SQLQuery sqlQuery = session.createSQLQuery("SELECT table.id, table.date FROM table");
List<Object[]> resultArray = sqlQuery.list();
Date date = (Date)resultArray[1];

If it was 26-feb-2010 17:59:16 in DB I'll get 26-feb-2010 00:00:00 How to get it with time?

+2  A: 

I am not an expert with Oracle, but you probably need a DateTime column type to get a time stamp.

With that you need to use java.sql.Timestamp JDBC type.

Alexander Pogrebnyak
In Oracle, the `DATE` datatype contains both date and time information, much like `java.lang.Date`.
Pascal Thivent
A: 

Try this:

session.createSQLQuery("SELECT table.id as i, table.date as d FROM table")
  .addScalar("i", Hibernate.LONG)  // Or whatever type id is
  .addScalar("d", Hibernate.TIMESTAMP);
Brian Deterling
Thanks. Now it works. But I hate the fact I should define types for all of the returned parameters there. I have quite a lot of them...
Vlad
You could try a custom dialect. The base dialect says "register hibernate types for default use in scalar sqlquery type auto detection" and has Types.DATE matched to Hibernate.DATE - you could subclass it and match Types.DATE to Hibernate.TIMESTAMP.
Brian Deterling
A: 

Maybe you have this problem? Make sure you have the latest JDBC driver, the filename should be ojdbc5.jar.

wallenborn
A: 

I had the same problem (Oracle Date type in the database).

The following mapping works for me:

<property name="timeStamp" type="java.util.Date">
    <column name="TIME_STAMP"/>
</property>
hansfbaier