I've got an issue with fields being cached in my application and i need to figure out how to dump that cache and get the value from the database. I've simplified my mappings for this post to get to the point. The "DetailText" class is used to separate ntext fields so that they load more efficiently due to their size. The problem is in my application, i update one of the fields (Description), and it does not update until either some cache expires or i touch the web.config to reset the web application. it would be nice to be able to just clear the nhibernate cache or whatever is going on. any ideas what i should do?
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
namespace="Com.WildTangent.ProductCatalog.Data"
assembly="ProductCatalog">
<class name="ProductLocale" table="t_ProductLocale" lazy="true">
<cache usage="read-write" />
<id name="Id" column="ProductLocaleId" type="int">
<generator class="native" />
</id>
<property name="DisplayName" type="String" length="64" column="DisplayName" not-null="false" />
<one-to-one name="DetailText" class="ProductDetailText" constrained="true" />
</class>
</hibernate-mapping>
Code:
public class ProductLocale
{
public virtual int Id
{
get { return _id; }
set { _id = value; }
}
public virtual string DisplayName
{
get { return _displayName; }
set { _displayName = value; }
}
public virtual string Description
{
get { return _detailText != null ? _detailText.Description : null; }
}
protected string _displayName;
protected ProductDetailText _detailText;
}
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
namespace="Com.WildTangent.ProductCatalog.Data"
assembly="ProductCatalog">
<class name="ProductDetailText" table="t_ProductLocale" lazy="true">
<cache usage="read-write" />
<id name="Id" column="ProductLocaleId" type="int">
<generator class="foreign">
<param name="property">ProductLocale</param>
</generator>
</id>
<!-- Note that NHibernate needs ntext fields to be mapped -->
<!-- as StringClob - if you map them as string, they'll be -->
<!-- truncated since the SQL will treat them as varchars. -->
<property name="Description" column="Description" type="StringClob" />
<property name="EditorReview" column="EditorReview" type="StringClob" />
<property name="Story" column="Story" type="StringClob" />
<one-to-one name="ProductLocale" class="ProductLocale" />
</class>
</hibernate-mapping>
Code:
public class ProductDetailText
{
public virtual int Id
{
get { return _id; }
set { _id = value; }
}
public virtual ProductLocale ProductLocale
{
get { return _productLocale; }
set { _productLocale = value; }
}
public virtual string Description
{
get { return _description; }
set { _description = value; }
}
public virtual string EditorReview
{
get { return _editorReview; }
set { _editorReview = value; }
}
public virtual string Story
{
get { return _story; }
set { _story = value; }
}
public override bool Equals(object obj)
{
ProductDetailText other = obj as ProductDetailText;
return other != null ? (
other.Description == Description &&
other.EditorReview == EditorReview &&
other.Story == Story) : false;
}
public override int GetHashCode()
{
return typeof(ProductDetailText).GetHashCode() ^
(Description != null ? Description.GetHashCode() : 0) ^
(EditorReview != null ? EditorReview.GetHashCode() : 0) ^
(Story != null ? Story.GetHashCode() : 0);
}
private int _id;
private string _description;
private string _editorReview;
private string _story;
private ProductLocale _productLocale;
}