-->
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.  [ 6 posts ] 
Author Message
 Post subject: Transient obj update, why add entry with null loadedState?
PostPosted: Thu May 26, 2005 11:22 am 
Regular
Regular

Joined: Thu Dec 02, 2004 10:42 am
Posts: 54
I found this in the method SessionImpl.DoUpdateMutable(),

Would it be better that the SessionImpl load the respective DB object by ID, and then create the EntityEntry with loadedState not just null, but the values from DB?

The reason I ask for this is we need to make a object transient to send from a remote interface, say WebService, the session will be closed after transfer the object out.

Client may update the transient object or may not, after that the transient object will be sent back to middle tier. The Middel Tier will open a new session, which will take the transient object to update databse. I'd like to let the session automatically check all the properties of the object with the one persisted, so that if no changes had made, no need to update.

On the other hand, for the 2nd session, if I use session.Save() instead of Update() for the transient object, it always do inserting, if SessionImpl can check the DB first, it shall have the ability know to update if the respective object existing.
----------------------------------

Is this issue a bug or Hibernate is the same and it has its purpose?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2005 11:30 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
What you want is done in Hibernate by using select-before-update, but it's not in NHibernate yet. It's done the current way to avoid the database query if it's not needed.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2005 11:55 am 
Regular
Regular

Joined: Thu Dec 02, 2004 10:42 am
Posts: 54
"to avoid the database query if it's not needed" That is what I guessed.

But for transient object, I think it's necessary to select-before-update. This extra query is necessary for data integrity. Especially currently, NHibernate insert the object anyways if I invoke save. That could cause trouble.

Anyways, I'd like to know when will this select-before-update be ported into NHibernate? Any plan before realease 1?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2005 5:12 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Why is the select query necessary? You can't have less than one query anyway. And you have transactions, optimistic concurrency, etc. to handle these problems. Select-before-update is planned for 1.0 as far as I remember, but when it will actually be done depends on how much time we have.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 27, 2005 9:22 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
orientphoebus wrote:
But for transient object, I think it's necessary to select-before-update. This extra query is necessary for data integrity. Especially currently, NHibernate insert the object anyways if I invoke save. That could cause trouble.


Can you give an example ?

When you say "select-before-update", do you mean that NHibernate should select the ID of the transient object to make sure it is not in the database ? In this case, there are two possibilities :

1- The ID is assigned by the App/NHibernate; this means that it is their responsability to validate the uniquiness of this ID
2- The ID is native, so the database will give a valid ID.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 27, 2005 10:26 am 
Regular
Regular

Joined: Thu Dec 02, 2004 10:42 am
Posts: 54
hi, Sorry,

I didn't understand session.SaveOrUpdate() and session.SaveOrUpdateCopy(). I was using session.Save() or session.Update() always.

That's why it didn't work. Now with SaveOrUpdateCopy(), everything is fine.

Thanks


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