-->
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: FlushMode.Never not working with Save method!!!!
PostPosted: Tue Jan 29, 2008 11:25 am 
Newbie

Joined: Tue Jun 12, 2007 1:25 pm
Posts: 11
Location: Brazil
Hi all,

I'm needing to work with some objects and not persist them into database. For this I set the FlushMode to Never, this works fine in Get, Update and Delete methods.
But when I call the Save method, the Nhibernate executes the insert to the database and this will cause some problems to my application.

Can anyone help me?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 29, 2008 11:44 am 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
Are you using an identity generator for the primary key of that object by any chance? NHibernate will need to save that record to the database in order to generate a key. NHibernate requires a key once the object is added to the session.

If you can change the generator to assigned NHibernate will no longer need to save that record to the database. However, you will be responsible for setting the primary key value of the object prior to saving it to the NHibernate session.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 29, 2008 2:54 pm 
Newbie

Joined: Tue Jun 12, 2007 1:25 pm
Posts: 11
Location: Brazil
Yes,
I'm using the identity generator, but I can use a composite key instead of. I will make the necessary changes, and test this solution.
I believe that it will solve my problem.

Thanks!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 07, 2008 12:48 pm 
Newbie

Joined: Tue Jun 12, 2007 1:25 pm
Posts: 11
Location: Brazil
Hi,

I made the changes and the NHibernate dont saves the record to the database.

But the NHibernate not found the record when I tryed to get him.
I use HQL to get the objects and the only method that find the record is the "Get" method. But the application must get that record in a list of objects, not just that record alone.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 07, 2008 1:20 pm 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
I'm guessing this is because you have not yet flushed the session containing these objects. You can't possibly run an HQL query (which actually runs against your database) and expect it to retrieve records which don't exist.

The reason why Get would work is that for any get/load it actually checks the session's identity map (first level cache) first, and if it is found there will return it. Therefore, you will not need to make the database call, and will still receive the item.

Now, by default NHibernate actually flushes the items of the type you are querying for before you run a query, however, you have set FlushMode to Never, therefore NHibernate will not flush these changes for you automatically.

In this case you either need to flush the session, or perform the filtering in memory.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 18, 2008 10:39 am 
Newbie

Joined: Tue Jun 12, 2007 1:25 pm
Posts: 11
Location: Brazil
jchapman wrote:
I'm guessing this is because you have not yet flushed the session containing these objects. You can't possibly run an HQL query (which actually runs against your database) and expect it to retrieve records which don't exist.

The reason why Get would work is that for any get/load it actually checks the session's identity map (first level cache) first, and if it is found there will return it. Therefore, you will not need to make the database call, and will still receive the item.

Now, by default NHibernate actually flushes the items of the type you are querying for before you run a query, however, you have set FlushMode to Never, therefore NHibernate will not flush these changes for you automatically.

In this case you either need to flush the session, or perform the filtering in memory.


Hi jchapman,

The programmer that uses this funcionality, found a way to use the "Get" method and the problem is solved. 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.