-->
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.  [ 1 post ] 
Author Message
 Post subject: Howto filter an many-to-many association from a session
PostPosted: Mon Sep 07, 2009 12:23 pm 
Newbie

Joined: Tue Nov 01, 2005 12:31 pm
Posts: 5
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.