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.  [ 2 posts ] 
Author Message
 Post subject: deleting entries by date type
PostPosted: Wed Feb 09, 2005 5:41 am 
Newbie

Joined: Tue Feb 08, 2005 4:16 am
Posts: 14
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hi!!

I have a table with a datetime column.
I try to delete entries with dates older the 2 hours.
my code is below.

The problem: entries that has the same date as today's but older then 2 hours are not deleted where as entries from yesterday or older are deleted. why?

From the sql statement I see a select is made but not a delete - is that a cache thing? if it is, how can I disable it?

how can I do this better?

Thanks
Yariv

Hibernate version:
2.0 - I know its old - can't upgrade for now.
Mapping documents:

Code between sessionFactory.openSession() and session.close():
// get current date
Date date = new Date();
// calculate the date x hours ago. (HOUR_IN_MILISEC = 3600000).
Date xHoursAgo = new Date(date.getTime() - (2 * HOUR_IN_MILISEC));

//set date and type for query
Date[] dates = new Date[] {xHoursAgo};
Type []dateTypes = new Type[]{new DateType()};

// run the db clean
Session session = getHibernateSession();// get session from thread local.
Transaction tx = session.beginTransaction();
session.delete("from com.mercury.dashboard.model.portlet.GeneratedImage as image where image.creationDate < :date", dates, dateTypes);
tx.commit();
Full stack trace of any exception that occurs:

Name and version of the database you are using:
sql server 2000 jtds1.0 driver
The generated SQL (show_sql=true):
11:16:34,770 INFO [STDOUT] Hibernate: select generatedi0_.GENERATED_IMAGE_ID as
GENERATE1_, generatedi0_.VERSION as VERSION, generatedi0_.CREATION_DATE as CREA
TION3_, generatedi0_.NAME as NAME, generatedi0_.IMAGE_DATA as IMAGE_DATA from DS
H_GENERATED_IMAGES generatedi0_ where (generatedi0_.CREATION_DATE<? )
Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject: deleting entries by date type
PostPosted: Thu Feb 10, 2005 10:27 am 
Newbie

Joined: Tue Feb 08, 2005 4:16 am
Posts: 14
Hi!!

Well it seem the answer lies in the type passed to the query.
Since the table column is a timestamp and not a date - the value and type passed to the query must be java.sql.Timestamp and TimestamType respectively.


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