-->
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.  [ 9 posts ] 
Author Message
 Post subject: Update question
PostPosted: Mon Dec 22, 2003 7:59 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
Hi everyone,

It's possible to execute such query :
Code:
UPDATE report SET deleted = ? WHERE updated_time < ?


There're lots of such report, so i can't select this reports and than update them in cycle.

I can do it getting sql prepare statement from Connection, but will there be any troubles with objects in cache ?

Thank's[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 9:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You should definitely do this by using a native SQL query. You should manually flush the cache afterwards.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 9:31 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
gloeglm wrote:
You should definitely do this by using a native SQL query. You should manually flush the cache afterwards.

How can i do it ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 10:04 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Code:
session.createSQLQuery(...)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 10:08 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
drj wrote:
Code:
session.createSQLQuery(...)

I mean how can i flush cache for some objects.
And createSQLQuery doesn't work. because it invokes "executeQuery", but when query is "update ...", you should invoke "execute".

Now i did such :
Connection conn = session.connection();
PreparedStatement ps = conn.prepareStatement("UPDATE report " +
" SET deleted = ? WHERE updated_time < ?");


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 10:15 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
oops - yes - createSQLQuery is for queries.

To refresh the session call session.refresh(Object yourobject)

Justin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 10:20 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
.. which may prove cumbersome for you as you may have multiple objects and thus need to iterate over all the objects.
As far as I know, there isn't a method to bulk-kick all objects of a given class out of the session cache. Anyone else know of a method (besides closing the session)?

Justin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 10:21 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
drj wrote:
.. which may prove cumbersome for you as you may have multiple objects and thus need to iterate over all the objects.
As far as I know, there isn't a method to bulk-kick all objects of a given class out of the session cache. Anyone else know of a method (besides closing the session)?

Justin

Not just closing session but also refreshing Ecache.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 10:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You can use session.clear() to clear the Session level cache, and SessionFactory.evictXXX() to clear the second level cache.


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