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.  [ 4 posts ] 
Author Message
 Post subject: About (Mass) Update
PostPosted: Thu Dec 11, 2003 10:21 pm 
Beginner
Beginner

Joined: Thu Dec 04, 2003 3:47 am
Posts: 31
Location: Hong Kong
I would like to do some update operation, say updating a column of all (or subset) or rows of the table. There are 2 approaches

1. Retreieve all the data objects, update the state of the data objects one by one, and the save

2. Use a single SQL statement to do the update

For approach 1, it would be having too much overhead. So certainly I prefer approach 2.

However, I have some question and not sure whether Hibernate supports it.

a. Can the "named query" be those update statement?
b. if not, can I (or by what mean) use Hibernate to do these kinds of update?
c. if I cannnot use Hibernate to do that, I can do the update through JDBC. However I would like to ask, after I do the update, would the cache in the Hibernate know about that? (say the update statement would update attributes of some data objects in the cache, would there be inconsistences?)
d. There is an update class in the Java API. Could anyone points me to some documentation or resources where I can find its detail usage?

Maybe someone has asked similar questions or there are documentation about these issues. If this is the case, could anyone point me to the related information? Many Thank!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 11:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Mass updates would normally be done using the JDBC connection, eg,
session.getConnection() or use the query interface and create a SQL query (see 2.1 docs).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 11:46 pm 
Beginner
Beginner

Joined: Thu Dec 04, 2003 3:47 am
Posts: 31
Location: Hong Kong
hi david,

Yes. I would like to use JDBC directly. But i'm wondering if I delete from using JDBC, could the cache in the Hibernate take care about that? (some data has been deleted from the database may have been retrieved and stayed in the hibernate cache before)

Also, for the Query class. I read from some previous post (about in July) that it does support query but not update statement. Has it be modified? It can be used for update now?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 11:58 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Using JDBC directly is the same as another application making the changes to the database so no 2nd level cached objects will be updated/removed. You could access the cache exernally and clear the contents.

You are correct about the createSQL query so you will have to use JDBC connection.


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