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.  [ 4 posts ] 
Author Message
 Post subject: Life of Hibernate Object(Entity Object)
PostPosted: Wed Dec 27, 2006 7:23 am 
Newbie

Joined: Wed Dec 27, 2006 6:24 am
Posts: 2
Location: India
Hi All,

can you please let me know what happens at the time of CACHING in Nhibernate. and what can i do if I want to persist that without using session or Viewstate

regards
TechWorks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 28, 2006 5:14 pm 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
You can do an .Evict() on the object it out of the current Session. I don't understand your CACHING question...check the docs for 'second-level cache' if you are talking about the cache implementation that moves separately from the first-level cache used during a Unit of Work (between Session.Flush() calls).
The second-level cache caches by values not objects and is very good. Check out Ayende's blog at www.ayende.com for some info about the second-level cache.
As far as 'persist without...session or ViewState' I assume you mean ASP.NET's session and not NHibernate's ISession? There are lots of caching options...Enterprise Library and so on if you want to do something separate from NHibernate's second-level cache.

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 29, 2006 9:52 am 
Newbie

Joined: Wed Dec 27, 2006 6:24 am
Posts: 2
Location: India
Thanks a lot for your reply.

But I am not to understand the solution you have proposed using the .Evict() Method. It will great help if you can provide any example for the same.

As, I want to persist the object(entity object) after the closing of ISession, hence I can't go for 'first-level' or 'second-level' caching. I have to use some other method.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 29, 2006 12:56 pm 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
The second-level cache will be available as long as the SessionFactory is available if you choose and doesn't flush when the first-level cache flushes.
To enable the second-level cache just add something like this to your class mapping:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    default-access="nosetter.camelcase-underscore"
    default-lazy="false">
 
  <class name="Timesheet,AssemblyName"
      table="Timesheet">

    [b]<cache usage="read-write"/>[/b]
    <id name="Id" access="property" unsaved-value="0" >
      <column name="Id"/>
      <generator class="native" />
    </id>


If you dont want to use NHibernates secondlevel cache options, you can just choose a cache provider like Enterprise Library Caching Application Block and use that...simply place the object in the cache during a unit of work and it'll be there even after your ISession closes.
The only thing you need to be sure of is reattaching the object to the next ISession you are working with using either
Code:
Session.Update(object)
for entities who were persisted to the Db or
Code:
Session.Lock(object,LockMode.None)
for new entitites.

_________________
If this helped...please remember to rate it!


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