-->
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.  [ 3 posts ] 
Author Message
 Post subject: Restricted list of joined objects
PostPosted: Wed May 31, 2006 2:18 am 
Newbie

Joined: Wed Apr 26, 2006 5:28 am
Posts: 18
NHibernate version: 1.0.2

Hello,

I have a problem. I have the following tables:

Code:
_____________________
|Bank                 |
|---------------------|
|id : Guid            |
|bankname : wchar(200)|
|_____________________|
          |
          |
         /|\
_____________________
|Constraint           |
|---------------------|
|id : Guid            |
|id_bank : Guid       |
|note : wchar(200)    |
|_____________________|


I mapped the tables like this:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="BankManager" assembly="BankManager">
   <class name="Bank" table="Bank">
      <id name="Id" type="System.Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
         <column name="id" sql-type="Guid" not-null="true" />
         <generator class="guid" />
      </id>
      <property name="BankName">
         <column name="bankname" length="200" not-null="true"/>
      </property>
      <map name="Constraints" table="Constraint">
         <key column="id_bank" />
         <index column="id" type="Guid"/>
         <one-to-many class="Constraint" />
      </map>
   </class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="BankManager" assembly="BankManager">
   <class name="Constraint" table="Constraint">
      <id name="Id" column="id" type="System.Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
         <generator class="guid" />
      </id>
      <property name="Name">
         <column name="name" length="200" not-null="false"/>
      </property>
      <property name="Note">
         <column name="note" length="200" not-null="false"/>
      </property>
   </class>
</hibernate-mapping>


Now I want to select the bank with the name "TestBank", therefor I use the HQL like this:
Code:
IQuery bankQuery = session.CreateQuery(
                        @"select b from Bank as b
                          where (b.bankname = :bankname)");
                     bankQuery.SetString("bankname", "TestBank");


The result is the right bank with a list of constraints. But now I'd like to filter the constraints so that I get a bank with a "smaller" list of Constraints. For example only the Constraints with a note like 'Hello Wo%' should selected into the list.

Ho can I do this?

_________________
=/\=

Live long and prosper


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 3:24 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You can't get a bank with a smaller set of constraints directly, but you can filter the bank.Constraints collection using ISession.CreateFilter(...).List(). This will return to you a different collection (a list) of all constraints of the given bank which satisfy your conditions. The original collection will be unchanged.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 5:50 am 
Newbie

Joined: Wed Apr 26, 2006 5:28 am
Posts: 18
sergey wrote:
You can't get a bank with a smaller set of constraints directly, but you can filter the bank.Constraints collection using ISession.CreateFilter(...).List(). This will return to you a different collection (a list) of all constraints of the given bank which satisfy your conditions. The original collection will be unchanged.


Hi,
I was afraid that I couldn't do this.

Anyway. thank you for your help.

_________________
=/\=

Live long and prosper


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

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.