-->
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.  [ 13 posts ] 
Author Message
 Post subject: updates in native sql?
PostPosted: Mon Jan 31, 2005 10:58 am 
Newbie

Joined: Fri Jan 16, 2004 9:32 am
Posts: 11
hello - i was looking through the documentation and i see that i can do queries (selects) in native sql. however i'd like to do an update in native sql (i want to do a mass update of objects that aren't currently in the session). can i do a native sql update in hibernate - or should i go directly through jdbc?
thanks for your time
chris


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 31, 2005 12:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
use session.connection()

In Hibernate 3.x there will be batch update available.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: What about objects status in the current session
PostPosted: Tue Feb 08, 2005 3:28 am 
Newbie

Joined: Wed Feb 02, 2005 3:01 am
Posts: 9
Max, what about objects status in the current session after commit() such mass updates to database ?!. I think this is an important issue to take care of.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 11, 2005 8:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
this cannot be done efficiently.

you either use the normal update features and have db and inmemory insync or use batch updating as the first thing you do in a session before querying/loading stuff....

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: flush() + clear() before natve update sql
PostPosted: Sat Feb 12, 2005 7:18 am 
Newbie

Joined: Wed Feb 02, 2005 3:01 am
Posts: 9
I have looked up forum for several opinions/investigations regarding this & found the following:
session.flush();
session.clear();
// Do your native sql batch updates /deletes here ..

Max, is this will make it effecient to be called anywhere in the session rather than at the start of session ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 5:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
calling .clear() is basically like resetting the session to be as it was in the beginning - but remember your objects are still not updated to reflect the changes you have done via your update/delete...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Status of session after callling session.clear()
PostPosted: Mon Feb 14, 2005 6:22 am 
Newbie

Joined: Wed Feb 02, 2005 3:01 am
Posts: 9
What do you think the status of already loaded objects after calling session.clear() ? what will be status in case of already loaded object tries to access one of its member fields/objects ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 6:28 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
sorry - i don't think I understand your question completly.....

are you asking what teh status of an already loaded object is after calling .clear ? Then it is detached - but that has nothing to do with your original question about performing bulk updates in sql.

Regarding what will be the "status" if an object loads its member fields/objects ? well - this is normal java so any fields it already has it can of course access. But if it fields/members/collections are not initialized at .clear time then accessing them will result in an exception since it cannot get to them (hence the "detached" status)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 10:54 am 
Newbie

Joined: Wed Feb 02, 2005 3:01 am
Posts: 9
Fine, this means the following:
1- Some hibernate Object ready & initialized in memory, lets Call it Object001.
1- session.flush(); // makes sure all pending scripts commited to DB
2- session.clear(); // detach all hibernate Objects because next step may make it invalid
3- Object001 is null with all its details nulled
4- Do native sql updates.
5- Hibernate session should reload Object001 to reflect point 4.

Am I right ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 11:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes for all points except i don't what #3 does....Object001 contains whatever was loaded from the db.

#5 i would rephrase to:
5 - The user should reget/load Object001 via the session to reflect possible changes done via point 4.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 11:43 am 
Newbie

Joined: Wed Feb 02, 2005 3:01 am
Posts: 9
OK, let me rephrase it:
1- Some Object loaded by hibernate ready & initialized in memory, lets Call it Object001.
2- session.flush(); // makes sure all pending scripts commited to DB
3- session.clear(); // detach all hibernate Objects from cache because native sql updates may make it invalid.
4- Object001 still has its values in point 1
5- Do native sql updates.
6- Object001 still has its values in point 1 which is now old & need to be refreshed.
7- User should reget/load Object001 via the session to reflect possible changes done via point 5.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 4:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes looks more like it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 4:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
note: #3 has no effect on #4-#7, it is just there to let you have a clean slate.

_________________
Max
Don't forget to rate


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