-->
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.  [ 10 posts ] 
Author Message
 Post subject: Oracle 9i, Hibernate 2, java.util.Date problems
PostPosted: Fri Jul 29, 2005 1:04 pm 
Newbie

Joined: Wed Aug 25, 2004 5:41 am
Posts: 9
Hibernate version: 2.1.8

Has anybody already experienced strange behaviour with Date fields using Hibernate 2.1.8 under Oracle 9i ?

I'm currently migrating from Oracle 8i to Oracle 9i and criteria based upon java.util.Date fields doesn't work anymore.

Yann


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 2:22 pm 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
What happens when it doesnt work? Stacktrace? Code? Etc? also, the type coming back from the DB might be a sql.Timestamp which is subclass of util.Date... Chris


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 3:53 am 
Newbie

Joined: Wed Aug 25, 2004 5:41 am
Posts: 9
Select by Criteria on Date field doesn't work anymore.

My test case is :

- Select an existing Evenement Object by Date Field And Id


Code:
<class
    name="com.orange.greco.persistance.dao.fiche.bean.EvenementTO"
    table="EVENEMENT"
>

    <id
        name="idEvenement"
        type="java.lang.Integer"
        column="ID_EVENEMENT"
    >
       <generator class="sequence">
         <param name="sequence">SEQEVE00</param>
      </generator>
    </id>
    <property
        name="datecreation"
        type="java.util.Date"
        column="DATECREATION"
        not-null="true"
        length="7"
    />
...
</class>


Code:
Criteria lookupCriteria = getHibernateTemplate().createCriteria(getSession(), EvenementTO.class);
lookupCriteria.add(Expression.eq("idEvenement",<EXISTING_ID_EVENEMENT>);
lookupCriteria.add(Expression.eq("datecreation",<EXISTING_DATE_CREATION>);
List results=lookupCriteria.list();
return results;



EXISTING_DATE_CREATION is the exact same java.util.Date object used for the creation of the Evenement Object that I try to select.

And select is always blank...

I have seen problems concerning handling of java.sql.timeStamp and TIMESTAMP sql type in Oracle 9i but It doesn't seem to apply to me as I use java.util.Date for Hibernate Mapping and DATE for the sql column type


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 5:38 am 
Newbie

Joined: Tue May 10, 2005 1:19 pm
Posts: 10
Hello Yann

This issue is closely related to the one I discussed recently in Sun's JDBC forum (http://forum.java.sun.com/thread.jspa?forumID=48&threadID=629746)

Essentially you need to convert the java.util.Date you are using to the same resolution as the datatype in Oracle (e.g. seconds for date).

In the same vein as your example above, we have:

// convert mills to seconds using integer arithmetic kludge
java.util.Date myModifiedDate =
new Date(((myOriginalDate.getTime()/1000)*1000));

lookupCriteria.add(Expression.eq("mydatefield", myModifiedDate));
List results=lookupCriteria.list();
System.out.println("results size: "+results.size()); // prints 1

Note that the way the Oracle drivers convert a java.util.Date for storage is not documented. I've always assumed they truncate rather than rounding, which is why I use the conversion method above. It appears to work but YMMV.

Regards

Jonathan.


Top
 Profile  
 
 Post subject: RE:
PostPosted: Mon Aug 01, 2005 7:51 am 
Newbie

Joined: Mon Aug 01, 2005 7:33 am
Posts: 18
Location: UK
I take it in the hibernate config file you have select Oracle9I dialect and not the Oracle dialect?? If you haven't then do so and this should fix the problem - I was having a similar prob but in trying to convert from 9i to 8i. Ummm if you are already using the 9i dialect then forgive me for intruding!

s


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 10:26 am 
Newbie

Joined: Wed Aug 25, 2004 5:41 am
Posts: 9
Problems seems to be solved by using Oracle 8i jdbc drivers ?????


Top
 Profile  
 
 Post subject: Ooops
PostPosted: Mon Aug 01, 2005 11:57 am 
Newbie

Joined: Mon Aug 01, 2005 7:33 am
Posts: 18
Location: UK
No I meant - make sure you ARE using the Oracle9i dialect - and not the Oracle dialect (which is pre 9i version) - sorry I got my words muddled!!

S :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 12:14 pm 
Newbie

Joined: Wed Aug 25, 2004 5:41 am
Posts: 9
In my previous post, I meant that my problem was actually solved by replacing jdbc drivers with Oracle 8i drivers ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 12:19 pm 
Newbie

Joined: Mon Aug 01, 2005 7:33 am
Posts: 18
Location: UK
OK - weird!! All I know is that when I looked at the hibernate source code for the different dialect classes is that there is an explicit workaround for the problem of converting between date types between 8i and 9i. How strange for you then?? So which dialect are you using now?? And the driver is 8 ey ... oh well if it is working what can I say??! :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 12:28 pm 
Newbie

Joined: Wed Aug 25, 2004 5:41 am
Posts: 9
Oracle 9i Dialect + Driver Jdbc Oracle 8i

Weird, but validated with 640 JUnit test cases ...


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