-->
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: Trouble using batch delete with paramater substitution
PostPosted: Thu Mar 03, 2005 7:39 pm 
Newbie

Joined: Tue Feb 24, 2004 6:07 pm
Posts: 4
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.1.6

Code between sessionFactory.openSession() and session.close():

Name and version of the database you are using: MySQL 4.1.8

The generated SQL (show_sql=true): select persistent0_.uid as uid, persistent0_.timestamp as timestamp, persistent0_.typename as typename from persistentstate persistent0_ where (persistent0_.timestamp<=? )

I'm trying to use batch delete ( session.delete(...) ) to delete a large number of objects. My code looks like this:


Code:
         String deleteQueryString = "from " + Database.NAME_OF_STATE + " e where e.timestamp <= ?";
         
         // Delete the requested entries
         session.delete(
               deleteQueryString,
                new Object[] { latestTimestamp },
                new Type[] { Hibernate.DATE }
         );


latestTimestamp is a Date object. Database.NAME_OF_STATE is my table, "PersistentState". When I look at the SQL generated, however, it comes out both on the console and in the debug log with the "?" parameter still intact:

Quote:
DEBUG [net.sf.hibernate.SQL] select persistent0_.uid as uid, persistent0_.timestamp as timestamp, persistent0_.typename as typename from persistentstate persistent0_ where (persistent0_.timestamp<=? )


None of the entries in the database appear to be affected. Nothing that I've tried seems to make the parameter get substituted. Trying too many parameters throws a "too many parameters" style error, and mismatching the parameter Type throws an appropriate error, so it looks like Hibernate is aware of the parameter, but I'm not really getting whether the parameter isn't getting substituted and the SQL is bad, or if I can't see what the SQL is that's being generated because the substitution is masked on output.

Am I missing something obvious?

Thanks,
- Ert[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 03, 2005 9:27 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
The show sql won't actually show you the values for the ? at any point. You need to set up your debug level to actually show that. Search the forums, there was a post recently (today?) asking about the debug levels if you are unsure.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 04, 2005 2:33 pm 
Newbie

Joined: Tue Feb 24, 2004 6:07 pm
Posts: 4
Ah, excellent, thanks. That's got it.

Now I see that the query is

Code:
select persistent0_.uid as uid, persistent0_.timestamp as timestamp, persistent0_.typename as typename from persistentstate persistent0_ where (persistent0_.timestamp<= '28 February 2005' )


...but mysql wants dates like '2005-02-28 15:58:02'. Off to figure out how to change DateType's parameter binding...


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.