-->
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.  [ 3 posts ] 
Author Message
 Post subject: ILifecycle and persistance checking
PostPosted: Thu Jul 24, 2008 7:20 am 
Newbie

Joined: Wed Jul 09, 2008 7:48 pm
Posts: 5
Ok. I have tried everything but can't get the below scenario to work.

I have a class that has a associated mapping file. This class has a property on it call CanSave, this will be false if NHibernate shouldn't save it.

The problem is how do I prevent NHibernate from automatically persisting an object where CanSave is false (this property isn't mapped in the mapping file and therefore I can't use discrimantor etc).

ILifecycle doesn't work as when I veto onSave NHibernate complains about the id being null!! (which is strange as it won't have an id for onSave)

Any ideas from any experts out there?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 24, 2008 7:35 am 
Regular
Regular

Joined: Mon Aug 29, 2005 3:07 pm
Posts: 77
Can't you use an Interceptor for this ?

Maybe (I haven't checked or tried this), you can remove the entities for whic h the CanSave property is set to false from the entity collection that is given in the PreFlush method of the interceptor ?

(BTW: ILifecylce should be obsolete).

/hm, i don't think it will work ...

What is the reason for this CanSave property ? I mean: in which cases should NHibernate not save your entity ? In other words: when do you set this property to false ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 24, 2008 7:45 am 
Newbie

Joined: Wed Jul 09, 2008 7:48 pm
Posts: 5
Thanks for the prompt reply.

The reason why I have this property is that these objects are being used like a cache and this cache object (which has the property CanSave) has a Value object property. This Value property may contain persistable data such as a string but also may contain something like a dataset.

Yes. I agree I could probably use Interceptor, but I would actually prefer the the behaviour of the object to be self contained.

Anyway why is ILifecycle depreciated? What was the thinking behind that


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