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: Strange Criteria Query Results.
PostPosted: Mon Apr 09, 2007 10:39 am 
Newbie

Joined: Mon Apr 09, 2007 10:29 am
Posts: 14
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
[b]NHibernate version 1.0.4.0[/b]

[b]<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="BusinessObjects.TestModule.TestPaper, BusinessObjects.TestModule" table="testpaper">
<id name="ID" column="ID" type="Int32">
<generator class="native"></generator>
</id>
<property name="Name" column="NAME" type="String" length="45" not-null="true"/>
<property name="Description" column="DESCRIPTION" type="String" not-null="true"/>
<property name="Status" column="STATUS" type="Boolean" not-null="true"/>
<property name="CreatedOn" column="CREATED_ON" type="DateTime" not-null="true"/>
<property name="ModifiedOn" column="MODIFIED_ON" type="DateTime" not-null="true"/>
<many-to-one name="CreatedBy" column="Created_By" class="BusinessObjects.UserModule.User, BusinessObjects.UserModule" not-null="true"/>
<many-to-one name="ModifiedBy" column="Modified_By" class="BusinessObjects.UserModule.User, BusinessObjects.UserModule" not-null="true"/>
<property name="DtpSubmittedOn" column="DTP_Submitted_On" type="DateTime" not-null="false"/>
<property name="ProofReadOn" column="ProofRead_ON" type="DateTime" not-null="false"/>
<many-to-one name="ProofReader" column="Proof_Reader" class="BusinessObjects.UserModule.User, BusinessObjects.UserModule" not-null="true"/>
<many-to-one name="DtpAllocated" column="DTP" class="BusinessObjects.UserModule.User, BusinessObjects.UserModule" not-null="true"/>
<property name="TestPhaseInt" column="Current_Phase" type="int" not-null="true"/>
<many-to-one name="Template" column="Template_ID" class="BusinessObjects.TestModule.Template, BusinessObjects.TestModule" not-null="true"/>

</class>
</hibernate-mapping>[/b]

I am firing this Criteria Query
ICriteria criteria = session.CreateCriteria(typeof(Testpaper));
criteria.Add(Expression.Like(Name, "new", MatchMode.Start));
return criteria.List();
and it gives me wierd results like sometimes it shows me 1 row twice and somtimes it has 20 repeats.
If i remove the template mapping ( <many-to-one name="Template" column="Template_ID" class="BusinessObjects.TestModule.Template, BusinessObjects.TestModule" not-null="true"/>
) then it shows correct results.
Template mapping file is

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="BusinessObjects.TestModule.Template, BusinessObjects.TestModule" table="template">
<id name="ID" column="ID" type="Int32">
<generator class="native"></generator>
</id>
<property name="Name" column="NAME" type="String" length="45" not-null="true"/>
<property name="Description" column="DESCRIPTION" type="String" not-null="true"/>
<property name="Status" column="STATUS" type="Boolean" not-null="true"/>
<property name="CreatedOn" column="CREATED_ON" type="DateTime" not-null="true"/>
<property name="ModifiedOn" column="MODIFIED_ON" type="DateTime" not-null="true"/>
<many-to-one name="CreatedBy" column="Created_By" class="BusinessObjects.UserModule.User, BusinessObjects.UserModule" not-null="true"/>
<many-to-one name="ModifiedBy" column="Modified_By" class="BusinessObjects.UserModule.User, BusinessObjects.UserModule" not-null="true"/>
<bag name="TemplateStructures" table="template_structure" outer-join="true" inverse="true" cascade="all-delete-orphan">
<key column="TEMPLATE_ID" />
<one-to-many class="BusinessObjects.TestModule.TemplateStructure, BusinessObjects.TestModule" />
</bag>
</class>
</hibernate-mapping>

Can some one tell me whats happening.
If i remove all the template entries from database it shows correct result so i have a feeling it might be a join problem

Thanx


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 09, 2007 10:41 am 
Newbie

Joined: Mon Apr 09, 2007 10:29 am
Posts: 14
I am using MySql as database


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 12, 2007 9:05 am 
Newbie

Joined: Mon Apr 09, 2007 10:29 am
Posts: 14
There are couple of more observations I have made.
1. If i use to retireve object collection using HQL it works fine with or without constraints.

2. Even the simple query as "session.CreateCriteria(typeof(TestPaper)).List()" is giving wrong results. Its giving more then the total number of rows present.
However if i put ".SetFetchMode("Template", FetchMode.Lazy)" then the results are fine for both contrained and non constrained version.

Is this a bug in criteria query as i think this "session.CreateCriteria(typeof(TestPaper)).List()" should give atleast the correct result.

Thanx in Anticipation

Saurabh


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.