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.  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Only generate SQL statements, is possible!?
PostPosted: Sun Aug 13, 2006 9:38 am 
Newbie

Joined: Sun Nov 20, 2005 10:23 am
Posts: 19
Hello all,

Does possible use the hibernate (and NHibernate) for only to generate SQL statements for changed objects !? I don't want that the Hibernate/NHibernate send statements for the SGDB.
If this is possible, how I get this statements's?!

Thank's...
FernandoVM


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 15, 2006 1:47 pm 
Newbie

Joined: Sun Nov 20, 2005 10:23 am
Posts: 19
Anybody know!? :(


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 15, 2006 3:48 pm 
Regular
Regular

Joined: Tue Feb 07, 2006 4:27 pm
Posts: 69
I'm not sure if this is what you are looking for, but use the following definitions on your persistent classes:

Code:
dynamic-insert="true"

Fields that have a value only will appear in the Insert statement

Code:
dynamic-update="true"


Only fields that have changes will be included in the Update statement


If you are hoping NHibernate will be able to inspect each of your objects and know which one has changed state since it was read from the DB, it doesn't do that to the best of my knowledge.

Hope this helps.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 2:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
gcook1@shaw.ca wrote:
If you are hoping NHibernate will be able to inspect each of your objects and know which one has changed state since it was read from the DB, it doesn't do that to the best of my knowledge.


eh, that is exactly what it does ;)


How else could e.g. dynamic-insert and dynamic-update work?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 7:04 am 
Newbie

Joined: Sun Nov 20, 2005 10:23 am
Posts: 19
Hi,

Thank's by attention... Well, in reality isn't this that I want. I want that the NHibernate don't establish a connection to a database for submit SQL statements, I want that it only generate this statements for I after submit it manually.

[]'s
FernandoVM


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 7:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so write a wrapper around a jdbc driver and collect the statements for you to execute later.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 8:03 am 
Regular
Regular

Joined: Tue Feb 07, 2006 4:27 pm
Posts: 69
max wrote:
gcook1@shaw.ca wrote:
If you are hoping NHibernate will be able to inspect each of your objects and know which one has changed state since it was read from the DB, it doesn't do that to the best of my knowledge.


eh, that is exactly what it does ;)


How else could e.g. dynamic-insert and dynamic-update work?


Actually, I thought he was asking if NHibernate kept track of the objects that were changed as you were changing them. You still need to initiate the SaveOrUpdate method for each object you change.

TOPLink for Java does it a little differenctly. It keeps track of the objects you change as you change them within your session cache. That is, the developer only needs to register his object(s) into his UnitOfWork make any change to these objects and then says commit. TOPLINK then inspects each object to see which ones have changed and then generates the dynamic SQL for the changes as required.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 8:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
eh, yes! But that is still how Hibernate (and nhibernate) works.

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 8:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
unitofwork = (more or less) Session

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 9:05 am 
Newbie

Joined: Sun Nov 20, 2005 10:23 am
Posts: 19
max wrote:
so write a wrapper around a jdbc driver and collect the statements for you to execute later.


This was the first thing in the wich I think, but I want know if thre are a way less intrusive... :)

Thank's by attention!

[]'s
FernandoVM


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 10:23 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
gcook1@shaw.ca wrote:
Actually, I thought he was asking if NHibernate kept track of the objects that were changed as you were changing them. You still need to initiate the SaveOrUpdate method for each object you change.


Actually, You do not need to. The SaveOrUpdate is needed only if the object is obtained trought the different session. Inside one session, only new objects must be Save()-d.

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 3:52 pm 
Regular
Regular

Joined: Tue Feb 07, 2006 4:27 pm
Posts: 69
Thanks guys. I didn't realize NHibernate did this within a single session. I like it even more now!

Greg


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 4:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
gert wrote:
Actually, You do not need to. The SaveOrUpdate is needed only if the object is obtained trought the different session. Inside one session, only new objects must be Save()-d.


...and that is not even needed if they are reachable over an cascadable association from an existing persistent object.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 9:40 am 
Newbie

Joined: Sun Nov 20, 2005 10:23 am
Posts: 19
I can't use directally the Hibernate O/R mapping class to only generate SQL statements without use the hibernate background (session, transactions e etc...) ?? This wold be very usefull to me... :)

[]'s
FernandoVM


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 9:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
eh what is so bad about using those api's to get it with ? :)

_________________
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.  [ 20 posts ]  Go to page 1, 2  Next

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.