-->
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: Hibernate many-to-many mapping based on multiple propert-ref
PostPosted: Fri Dec 11, 2009 5:37 am 
Beginner
Beginner

Joined: Sun Oct 22, 2006 12:06 pm
Posts: 39
Given the following mappings I would need to add aditional citerias to many-to-many element.
Code:
<hibernate-mapping>
<class name="ee.volis.entity.Koosseis" table="user_membership">
   <id name="id" column="koosseis_id" type="long"><generator class="sequence"><param name="sequence">user_membership_koosseis_id_seq</param></generator></id>
   <property name="start_date" column="start_date" type="timestamp"/>
   <property name="end_date" column="end_date" type="timestamp"/>
   <many-to-one name="company" column="company_id" class="ee.volis.entity.company"/>
   
   <set name="members" lazy="true" inverse="true"  table="user_groups">
         <key column="company_id" property-ref="company"/>
         <many-to-many column="group_id" property-ref="group" class="ee.volis.entity.GroupMember" where="1=1" ></many-to-many>
   </set>   
</class>

<class name="ee.volis.entity.GroupMember" table="asutused.group_member">
   <id name="id" column="group_member_id" type="long"><generator class="sequence"><param name="sequence">asutused.group_member_group_member_id_seq</param></generator></id>   
   <property name="start_date" type="timestamp" column="start_date"/>
   <property name="end_date" type="timestamp" column="end_date"/>
   <many-to-one name="grupp" class="ee.volis.entity.Grupp" column="grupp_id"/>
</class>
</hibernate-mapping>

when executing query "from ee.volis.entity.Koosseis" and iterating through the collection I need to have only the active group members that are constrainted
by ee.volis.entity.Koosseis start and end dates and Koosseis company.

Right now I can get only bound elements by company

Question is how can I add multiple property-ref criterias to where clause
The current situation will print out following hibernate sql clause
Code:
select *
from user_groups members0_
left outer join companyed.group_member groupmember1_ on members0_.group_id=groupmember1_.group_id
where  ( 1=1) and
members0_.company_id=?


but I would need that hibernate would execute the query with following aditionial where clause parameters like
Code:
select *
from user_groups members0_
left outer join companyed.group_member groupmember1_ on members0_.group_id=groupmember1_.group_id
where  ( start_date between :start_date and :end_date and end_date between :start_date and :end_date) and members0_.company_id=?


(:start_date, :end_date) would be referenced values from user_membership associated class like it is done for members0_.company_id=?

so is there any way to add multiple parameters from association class something like this
Code:
<set name="members" lazy="true" inverse="true"  table="user_groups">
   <key column="membership_start_date" property-ref="start_date"/>
   <key column="membership_end_date" property-ref="end_date"/>
   <key column="membership_start_date" property-ref="start_date"/>
   <key column="membership_end_date" property-ref="end_date"/>
   <key column="company_id" property-ref="company"/>   
   <many-to-many column="group_id" property-ref="group" class="ee.volis.entity.GroupMember" where="start_date between ? and ? and end_date between ? and ?" ></many-to-many>
</set>


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.