Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate property formula filter

I have a following class:

MyClass
public virtual int Id { get; set; }
public virtual int Code { get; set; }
public virtual int Description { get; set; }
public virtual int Name { get; set; }

with the following mapping:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="TestApplication" assembly="TestApplication">
  <class name="MyClass" table="MyTable">
    <id name="Id" column="id">
      <generator class="native"/>
    </id>

    <property name="Code" column="code"/>
    <property name="Description" column="description"/>
    <property name="Name" formula="(SELECT b.translation FROM translations b WHERE b.translation_id = translation_id AND b.language_id = :TranslationFilter.LanguageId)"/>
  </class>

  <filter-def name="TranslationFilter">
    <filter-param name="LanguageId" type="Int32"/>
  </filter-def>
</hibernate-mapping>

I'm trying to load entity through spring with:

Session.EnableFilter("TranslationFilter").SetParameter("LanguageId", 1);
return Session.Get<MyClass>(1);

but I'am getting adoexception. I see (in a profiler) that variable :TranslationFilter.LanguageId is not replaced with ? and that parameter value is not send to the server?

Is it this possible (to have filters in formula) and how?

Many thanks!

like image 879
rrejc Avatar asked May 20 '09 11:05

rrejc


1 Answers

This feature is not officially supported. As such oren's blog post about this combination of 2 different features (formulas and filters) should be taken with a grain of salt...

like image 120
Jaguar Avatar answered Oct 04 '22 05:10

Jaguar