-->
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: Criteria Problem
PostPosted: Wed Nov 22, 2006 12:24 pm 
Beginner
Beginner

Joined: Wed Nov 22, 2006 5:59 am
Posts: 29
Location: London
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

1.2.0 Beta 1

Mapping documents:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
namespace="BCS.Communications.Data.Tables" assembly="BCS.Communications.Data">
<class name="Destination">
<id name ="DestinationId" column="DestinationId" type="int">
<generator class="native" />
</id>
<property name="Address" type="string"/>
<property name="Role" column="Role" type="BCS.Communications.Data.Tables.RoleType, BCS.Communications.Data" length="500" not-null="true" />
<property name="Status" column="Status" type="BCS.Communications.Data.Tables.StatusType, BCS.Communications.Data" length="500" not-null="true" />
<many-to-one name="TransportId" class="Transport" column="TransportId" foreign-key="fk_destination_transport" />
</class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
namespace="BCS.Communications.Data.Tables" assembly="BCS.Communications.Data">
<class name="Transport">
<id name ="TransportId" column="TransportId" type="int">
<generator class="native" />
</id>
<property name="Description" type="string" />
<property name="Xml" type="string" />
<property name="TransportService" type="BCS.Communications.Data.Tables.ServiceType, BCS.Communications.Data" />
<bag name="Destinations" cascade="all" fetch="join" inverse="true">
<key column="TransportId" foreign-key="fk_destination_transport"/>
<one-to-many class="Destination" />
</bag>
</class>
</hibernate-mapping>




I'm having problems with retrieving an object using Criteria. The problem is if I create a Transport object and add 2 destinations to this object when I use criteria to retrieve the Transport object by Description I get two copies of the same object returned and they both have the two Destination objects in their destination collections. The amount of copies of the Transport object which are returned depends on how many Destinations I add to it. E.g if I add 2 Destination objects to a Transport object I get 2 copys of Transport when I query but if I add 3 Destinations I get 3 copies and so on. Here is the code I'm using to test this.



Code:
        public void TestMessageInsert()
        {

            ISession session = NHibernateHelper.GetCurrentSession();
            Transport t = new Transport();
            t.Description = "Test";
            t.Xml = "";
            t.AddDestination(new Destination());
            t.AddDestination(new Destination());
            session.SaveOrUpdateCopy(t);
            ICriteria criteria = session.CreateCriteria(typeof(Transport));
            criteria.Add(Expression.Eq("Description", "Test"));
            IList<Transport> result = criteria.List<Transport>();
        }
[/code]


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.