-->
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: Hibernate 3 (EJB3) and oracle date
PostPosted: Wed Nov 29, 2006 4:53 pm 
Newbie

Joined: Tue Jan 11, 2005 12:58 pm
Posts: 15
I am have trouble with selecting the maximum timestamp from a oracle date field in a table. I am using oracle database, hibernate 3 annotations and the entitymanager.

The Field ddl is as follows
"UPDTIME" DATE

The class field definition is as follows
@Column(name = "UPDTIME")
private Timestamp updtime;

The follow is the select that I am doing
Code:
Query query = entityManager.createQuery("select o from Transaction o where o.updtime in "
                + "(select max(t.updtime) from Transaction t where rate = ?)");
        query.setParameter(1, rate.trim());
       
        Transaction transaction = (Transaction)query.getSingleResult();


I am trying to find the last transaction with a particular rate. The transactions were initially saved with the system timestamp.

The above sql returns the first transaction always instead of the latest objects because the table doesnt store the timestamp but a date (DD-MMM-YYYY). Is there a way to do a select max(to_char(t.updtime, 'YYYYMMDD HH24:MM:SS') from Transaction t or something similar in order to get the required result?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 5:59 pm 
Senior
Senior

Joined: Sat Nov 27, 2004 4:13 am
Posts: 137
did you test using @Temporal annotation?

_________________
don't forget to credit!

Amir Pashazadeh
Payeshgaran MT
پايشگران مديريت طرح
http://www.payeshgaran.co
http://www.payeshgaran.org
http://www.payeshgaran.net


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 10:34 am 
Newbie

Joined: Tue Jan 11, 2005 12:58 pm
Posts: 15
Thanks that worked.
Code:
    @Column(name = "UPDTIME")
    @Temporal(TemporalType.TIMESTAMP)
    private Date updtime;


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.