Yes, you can use dynamic filters in combination with interceptors.
http://nhforge.org/wikis/howtonh/contextual-data-using-nhibernate-filters.aspx
For all the entities that have such an isDeleted property, I'd let them implement a certain interface where this property is defined.
For instance:
interface ISoftDeletable
{
bool IsDeleted { get; }
}
class SomeEntity : ISoftDeletable {}
(note that i use C# to explain my point, but I guess it'll be quite similar in java)
Then, you can define a filter-definition when creating your Hibernate configuration:
var softDeleteFilterParametersType = new Dictionary<string, NHibernate.Type.IType> (1);
softDeleteFilterParametersType.Add ("p_isDeleted", NHibernateUtil.Bool);
cfg.AddFilterDefinition (new FilterDefinition("SoftDeleteFilter", ":p_isDeleted = isDeleted", softDeleteFilterParametersType, false);
Then, you should add the filter to each mapped class that implements the ISoftDeletable interface:
foreach( var m in cfg.ClassMappings )
{
if( typeof(ISoftDeletable).IsAssignableFrom (m.MappedClass) )
{
Property delColumn = m.GetProperty ("IsDeleted");
m.AddFilter ("SoftDeleteFilter", ":p_isDeleted = " + delColumn.ColumnIterator.First().Name);
}
}
Then, you still have to create an interceptor which sets the value of the parameter to true or false, depending on what you want to do.
Perhaps you can even hardcode the value of the parameter in your filterclause (if you always want to retrieve non-deleted items), which would make the code above simpler I guess.