-->
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.  [ 5 posts ] 
Author Message
 Post subject: could not resolve property:
PostPosted: Fri Jan 23, 2009 11:49 am 
Newbie

Joined: Fri Jan 23, 2009 11:35 am
Posts: 3
I have a little issue and was wondering if someone can point me in the right direction or have a resolution for this issue.

I have never user Hibernate before and iam picking this work up from some other developer, i have other orm tools in the past.

I have a HQL Query which return me a list os studies. The studies table is joined to a contract and a test article tables.

I get this error on the last line of this code :

could not resolve property: Contract of: Bio.Domain.Model.TestArticle

Code:
if (req.bApplyFilter)
{

crit = crit.Add(Expression.Sql("{alias}.StudyManager = " + req.sFilter_StudyManager.ToString()));
crit = crit.Add(Expression.Eq("ProvisionalStartDate", req.sFilter_ProvisionalStartDate));
crit = crit.Add(Expression.Eq("ActualStartDate", req.sFilter_ActualStartDate));
crit = crit.Add(Expression.Eq("EndDate", req.sFilter_EndDate));
crit = crit.Add(Expression.Eq("FinalReportDate", req.sFilter_FinalReportDate));
crit = crit.CreateCriteria("TestArticle").Add(Expression.InsensitiveLike("ArticleName", req.sFilter_TestMaterialName, MatchMode.Anywhere));
crit = crit.CreateCriteria("Contract").Add(Expression.Sql("{alias}.ClientID = " + req.sFilter_SponsorNumber));

}

req.studies = (List<Study>)crit.List<Study>();


Any help with this issue would be superb.....cheers


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2009 1:18 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
The speciufic error is basically saying NH cannot resolve the property TestArticle.Contract. Can you please post the mapping files for TestArticle and Contract objects?

I realize you may be new so you're probably looking for a TestArticle.hbm.xml and Contract.hbm.xml. If you do not see those files in your code base, then perhaps the previous developer was using decoration and placed the mappings directly in the POCO. In that case, please post TestArticle.cs and Contract.cs. Sorry if you already knew that part.

-d


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 6:59 am 
Newbie

Joined: Fri Jan 23, 2009 11:35 am
Posts: 3
Hi deveonl

Thanks for replying, here is the 2 files you asked for

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Bio.Domain.Model" assembly="Bio.Domain" default-lazy="false">
<class batch-size="100" name="TestArticle, Bio.Domain" table="TestArticle">
<id name="ID" type="Int32" column="Id" unsaved-value="0">
<generator class="identity" />
</id>
<version column="version" type="Int64" unsaved-value="-1" name="Version" />
<many-to-one fetch="join" name="Study" column="StudyId" class="Study, Bio.Domain" not-null="false"/>
<property name="ArticleName" column="ArticleName" type="String" />
<property name="LicensedProductName" column="LicensedProductName" type="String"/>
<property name="ArticleVolume" column="ArticleVolume" type="String" />
<property name="Description" column="Description" type="String" />
<property name="StorageCondition" column="StorageCondition" type="String" />
<property name="BatchNumber" column="BatchNumber" type="Int32"/>
<property name="IsGMO" column="IsGMO" type="Boolean" />
<property name="Comments" column="Comments" type="String" />
<property name="TestArticleComplete" column="Complete" type="Boolean"/>
<property name="TestMaterialLabeling" column="TestMaterialLabeling" type="String" />
<many-to-one fetch="join" name="TestArticleCompletedBy" column="CompletedBy" class="User, Bio.Domain"/>
<many-to-one fetch="join" name="RiskAssessmentDocument" column="RiskAssessmentDocument" class="Document, Bio.Domain"/>

</class>
</hibernate-mapping>




<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Bio.Domain.Model" assembly="Bio.Domain" default-lazy="false">
<class batch-size="100" name="Contract, Bio.Domain" table="Contract">
<id name="ID" type="Int32" column="Id" unsaved-value="0">
<generator class="identity" />
</id>
<version column="version" type="Int64" unsaved-value="-1" name="Version" />
<bag batch-size="100" name="ContractAssays" inverse="true" cascade="all-delete-orphan">
<key column="ContractId" />
<one-to-many class="Assay, Bio.Domain" />
</bag>
<bag batch-size="100" name="ContractStudies" inverse="true">
<key column="ContractId" />
<one-to-many class="Study, Bio.Domain" />
</bag>
<!--
<bag batch-size="100" name="BioNotes" inverse="true">
<key/>
<one-to-many class="BioNote, Bio.Domain"/>
<loader query-ref="GetContractBioNotes"/>
</bag>
-->
<property name="ContractName" column="ContractName" type="String" />
<many-to-one fetch="join" name="sponsor" column="ClientId" class="Sponsor, Bio.Domain" />
<many-to-one fetch="join" name="SponsorContact" column="SponsorContactID" class="Contact, Bio.Domain" />
<many-to-one fetch="join" name="QuoteTemplate" column="QuoteTemplate" class="DocumentTemplate, Bio.Domain" />
<property name="ContractNumber" column="ContractNumber" type="Int32" />
<property name="ContractCreatedDate" column="ContractCreatedDate" type="DateTime"/>
<property name="ContractDiscount" column="ContractDiscount" type="Decimal" />
<property name="ContractAdditionalInformation" column="ContractAdditionalInformation" type="String" />
<property name="ContractLegalText" column="ContractLegalText" type="String" />
<property name="RepeatProject" column="RepeatProject" type="Boolean"/>
<property name="ContractCurrency" column="ContractCurrency" type="String"/>
<!-- Workflow status fields -->
<property name="ContractState" column="ContractState" type="Int32"/>
<!-- Quote approval -->
<property name="QuoteApprovedOn" column="QuoteApprovedOn" type="DateTime"/>
<many-to-one fetch="join" name="QuoteApprovedBy" column="QuoteApprovedBy" class="User, Bio.Domain" />
<!-- Quote delivered to client -->
<property name="QuoteDeliveredToClient" column="QuoteDeliveredToClient" type="Boolean"/>
<property name="QuoteDeliveredByPost" column="QuoteDeliveredToClientByPost" type="Boolean" />
<many-to-one fetch="join" name="QuoteDeliveredBy" column="QuoteDeliveredBy" class="User, Bio.Domain"/>
<property name="QuoteSentDate" column="QuoteSentOn" type="DateTime"/>
<!-- Quote received from client -->
<many-to-one fetch="join" name="QuoteSignedByClientDoc" column="QuoteSignedByClientDoc" class="Document, Bio.Domain" cascade="delete-orphan"/>
<property name="QuoteSignedByClientDocReceivedOn" column="QuoteSignedByClientDocReceivedOn" type="DateTime"/>
<many-to-one fetch="join" name="QuoteSignedByClientDocUploadedBy" column="QuoteSignedByClientDocUploadedBy" class="User, Bio.Domain"/>
<property name="QuoteRejected" column="QuoteRejected" type="Boolean"/>
<property name="QuoteRejectedReasons" column="QuoteRejectedReasons" type="String"/>
<!-- FinalQuote -->
<many-to-one fetch="join" name="FinalQuoteDoc" column="FinalQuoteDoc" class="Document, Bio.Domain" cascade="delete-orphan"/>
<property name="FinalQuoteUploadedOn" column="FinalQuoteUploadedOn" type="DateTime"/>
<many-to-one fetch="join" name="FinalQuoteUploadedBy" column="FinalQuoteUploadedBy" class="User, Bio.Domain"/>
<!-- Project Generated-->
<property name="ProjectGeneratedOn" column="ProjectGeneratedOn" type="DateTime" not-null="false"/>
<many-to-one fetch="join" name="ProjectGeneratedBy" column="ProjectGeneratedBy" class="User, Bio.Domain"/>
</class>
<sql-query name="GetContractBioNotes">
<return alias="bn" class="BioNote, Bio.Domain"/>
select {bn.*}
from BioNote bn
where bn.id in (select bnp.BioNoteId
from BioNoteProject bnp
where bnp.ContractId = :id)
</sql-query>
</hibernate-mapping>

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 8:26 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
crit.CreateCriteria returns a subcriteria. Try it this way:

Code:
crit.Add(Expression.Sql("{alias}.StudyManager = " + req.sFilter_StudyManager.ToString()));
crit.Add(Expression.Eq("ProvisionalStartDate", req.sFilter_ProvisionalStartDate));
crit.Add(Expression.Eq("ActualStartDate", req.sFilter_ActualStartDate));
crit.Add(Expression.Eq("EndDate", req.sFilter_EndDate));
crit.Add(Expression.Eq("FinalReportDate", req.sFilter_FinalReportDate));
crit.CreateCriteria("TestArticle").Add(Expression.InsensitiveLike("ArticleName", req.sFilter_TestMaterialName, MatchMode.Anywhere));
crit.CreateCriteria("Contract").Add(Expression.Sql("{alias}.ClientID = " + req.sFilter_SponsorNumber));

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 9:26 am 
Newbie

Joined: Fri Jan 23, 2009 11:35 am
Posts: 3
Thanks woli,

Working perfectly now thanks very much.


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