Hi,
I've Fault's and Tenants.
Code:
<hibernate-mapping>
<class name="de.itemis.Fault" table="FAULT">
<id name="id" type="long">
<generator class="native"/>
</id>
<property name="tn" length="255"/>
<set name="tenants" table="FAULT_TENANT" cascade="save-update" fetch="join" lazy="false">
<key column="FAULT"/>
<many-to-many column="TENANT" class="de.itemis.mitgas.stm.backend.userManagement.domain.Tenant"/>
</set>
<filter name="tenant_filter" condition="tenants IN (:tenants)"/>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class name="de.itemis.Tenant" table="Client">
<id name="id" type="long">
<generator class="native"/>
</id>
<property name="name" length="255" not-null="true"/>
</class>
</hibernate-mapping>
I would now use a hibernate filter, to filter all faults in all queries in the current session. The filter is defined as
Code:
<bean class="org.springframework.orm.hibernate3.FilterDefinitionFactoryBean">
<property name="filterName" value="tenant_filter"/>
<property name="parameterTypes">
<props>
<prop key="tenants">long</prop>
</props>
</property>
</bean>
Now I activate this filter in the session and I got the following exception:
Code:
org.hibernate.QueryException: illegal attempt to dereference collection [{synthetic-alias}{non-qualified-property-ref}tenants] with element property reference [id] [from de.itemis.Fault where tenants.id IN (1,2)]
at org.hibernate.hql.ast.tree.DotNode$1.buildIllegalCollectionDereferenceException(DotNode.java:46)
at org.hibernate.hql.ast.tree.DotNode.checkLhsIsNotCollection(DotNode.java:512)
To solve this dereferencing problem I could call something like
Code:
mySession.createQuery("from Fault as f left join f.tenants t where t.id IN (1,2)")
but how could I implement this as hibernate session filter?
Does anybody have an idea?
Thanks for all thoughts.
Regards