-->
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.  [ 6 posts ] 
Author Message
 Post subject: Selecting data from child table with column IsAvtive = T
PostPosted: Mon Sep 15, 2008 2:24 am 
Newbie

Joined: Tue Sep 09, 2008 3:20 am
Posts: 17
Hi,

How do I retrieve data from child table having IsActive column = "T"?
I have two tables Patients And Contact, Contact is the child table of patient. I am using the billow query to retrieve the data


Code:
IQuery query = session.CreateQuery("from Patient as pat where pat.IsActive= 'T' ");


This query returns all patient with IsActive = "T" and all there contacts even if IActive = "F". How do I retrieve only those contacts with IsActive = "T".

Thanks

Arvind


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2008 6:18 am 
Newbie

Joined: Tue Sep 09, 2008 3:20 am
Posts: 17
Searching for the solution i found billow code i used to retrive only active rows

Code:
ICriteria criteria = session.CreateCriteria(typeof(MagnumCore.Patient))
            .CreateAlias("Patient", "patient")
            .CreateAlias("patient.Contact", "patientcontact")
            .Add(Expression.Eq("patient.DocNum", patientId))
            .Add(Expression.Eq("patientcontact.DocIdPatients", "patient.DocId"))
            .Add(Expression.Eq("patientcontact.IsActive", "'T'"));


but when i use this i get the following error could not resolve property: Patient of: MyProject.Patient.

I also tryed this

Code:
IQuery query = session.CreateQuery("from Patient as pat inner join pat.PatientContact as PatCon where pat.DocNum= '" + patientId + "' and PatCon.IsActive='T'");


I get this error "The value \"System.Object[]\" is not of type \"MagnumCore.Patient\" and cannot be used in this generic collection.\r\nParameter name: value"}


Is there anything i have to do with this, or is there any other way to achive this?

Thanks

Arvind


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 9:11 am 
Newbie

Joined: Tue Sep 09, 2008 3:20 am
Posts: 17
Hi,

There was error in the criteria query after changing to billow query

ICriteria criteria = session.CreateCriteria(typeof(MagnumCore.Patient))
.Add(Expression.Eq("DocNum", patientId)).CreateCriteria("PatientContact")
.Add(Restrictions.Eq("IsActive", isActive));


My query worked and returned patient with contacts, instead of returning only those contacts whose IsActive= T, I get all the contacts for the patient , i.e. it is not applying any condition to the contact. Is there anything i have missed in this ?

Thanks

Arvind


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 9:12 am 
Newbie

Joined: Tue Sep 09, 2008 3:20 am
Posts: 17
Hi,

There was error in the criteria query after changing to billow query it worked.

ICriteria criteria = session.CreateCriteria(typeof(MagnumCore.Patient))
.Add(Expression.Eq("DocNum", patientId)).CreateCriteria("PatientContact")
.Add(Restrictions.Eq("IsActive", isActive));


My query worked and returned patient with contacts, instead of returning only those contacts whose IsActive= T, I get all the contacts for the patient , i.e. it is not applying any condition to the contact. Is there anything i have missed in this ?

Thanks

Arvind


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 10:33 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
have a look at the doc:

http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/querycriteria.html#querycriteria-associations

You query basically queries Patients and retrieves all Patients who have at least on PatientContact that matches your criteria. But the Patients are "fully" loaded, meaning all PatientContacts, not only those that match the criteria. If you want them filtered you need to use a result transformer:

SetResultTransformer(CriteriaUtil.AliasToEntityMap)


I never used it so I can't help you with the usage. But hopefully the rest of the answers helps you understand why you get what you get.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 10:37 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You can use filter to filter out inactive items. This approach is a bit different than including it in the criteria/query:

http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/filters.html

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.