-->
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: Criterion framework with Many-to-Many
PostPosted: Fri Apr 29, 2005 5:55 am 
Newbie

Joined: Fri Apr 29, 2005 5:38 am
Posts: 3
I have a many-to-many association in my DB and want to retrieve my objects via the Query by Criteria (QBC).

I didnĀ“t found some code performing QBC with many-to-many.

Here are my mapping-documents and my Criteria and would be very happy about some more tips or code examples. If you need more information, please tell it to me.

Regards,
Saemmy


Hibernate version: 3.0

Mapping documents:
<hibernate-mapping default-access="field">
<class name="model.BusinessDivision" lazy="true" table="BusinessDivision">
<cache usage="nonstrict-read-write"/>
<id name="id">
<generator class="assigned"/>
</id>
<version name="dbVersion"/>
<property name="description" not-null="false" length="40"/>
</class>

<class name="model.BDSubProject" lazy="true" table="EttmSubProject">
<cache usage="nonstrict-read-write"/>
<id name="pspElement" length="24">
<generator class="assigned"/>
</id>
<version name="dbVersion"/>
<set name="businessDivisions" table="Bd_BusinessDiv" fetch="join">
<cache usage="nonstrict-read-write"/>
<key column="pspElement"/>
<many-to-many class="model.BusinessDivision" column="BusinessDiv_id" fetch="select"/>
</set>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Criteria crit = session.createCriteria(EttmSubProject.class);
//crit.setFetchMode("businessDivisions", FetchMode.JOIN);
//crit.add(Expression.eq("businessDivision", businessDivision));
if (!StringUtils.isEmpty(pspElement))
{
crit.add(Expression.like("pspElement", pspElement);
}
crit.setMaxResults(limit);
crit.addOrder(Order.asc("pspElement"));
return crit.list();


Name and version of the database you are using:
MySQL
Oracle


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.