-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem using Criteria Queries
PostPosted: Mon Apr 10, 2006 8:56 am 
Newbie

Joined: Mon Apr 10, 2006 8:45 am
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
NHibernate 1.0
Mapping documents:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Jas.SalesLeads.BusinessRules.Branch,Jas.SalesLeads.BusinessRules" table="tbBranch">

<id name="BranchId" column="BranchId" type="String">
<generator class="assigned"/>
</id>
<timestamp column="Timestamp" name="Timestamp"/>
<property column="BranchName" type="String" name="BranchName" not-null="true"/>
<many-to-one name="Area" column="AreaId" not-null="true" class="Jas.SalesLeads.BusinessRules.Area, Jas.SalesLeads.BusinessRules" />

<bag name="UserRoleBranchManagers" table="tbRelBranchManagers">
<key column="BranchId" />
<many-to-many column="UserRoleId" class="Jas.SalesLeads.BusinessRules.UserRoles.IUserRole, Jas.SalesLeads.BusinessRules"/>
</bag>
</class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Jas.SalesLeads.BusinessRules.SalesLeadItem,Jas.SalesLeads.BusinessRules" table="tbSalesLeadItem">
<id name="SalesLeadId" column="SalesLeadId" type="Int64">
<generator class="identity">
</generator>
</id>
<timestamp column="Timestamp" name="Timestamp"/>
<property column="InsertDateTime" type="DateTime" name="InsertDateTime"/>
<property column="Shipper" type="String" name="Shipper" not-null="true"/>
<property column="ShipperPIC" type="String" name="ShipperPIC" not-null="true"/>
<property column="ShipperLocation" type="String" name="ShipperLocation" not-null="true"/>
<property column="ShipperPhone" type="String" name="ShipperPhone" not-null="true"/>
<property column="Consignee" type="String" name="Consignee" not-null="true"/>
<property column="ConsigneeLocation" type="String" name="ConsigneeLocation" not-null="true"/>
<property column="ConsigneePIC" type="String" name="ConsigneePIC" not-null="true"/>
<property column="ConsigneePhone" type="String" name="ConsigneePhone" not-null="true"/>
<property column="LastStatusChange" type="DateTime" name="LastStatusChange" not-null="true" />
<property column="OriginOfGoods" type="String" name="OriginOfGoods" not-null="true" />
<property column="DestinationOfGoods" type="String" name="DestinationOfGoods" not-null="true" />
<property column="Broker" type="String" name="Broker" not-null="true" />
<property column="Commodity" type="String" name="Commodity" not-null="true" />
<property column="TrafficVolume" type="String" name="TrafficVolume" not-null="true" />
<property column="Service" type="String" name="Service" not-null="true" />
<property column="Notes" type="String" name="Notes" not-null="true" />

<many-to-one name="Status" column="StatusId" class="Jas.SalesLeads.BusinessRules.SalesLeadStatus, Jas.SalesLeads.BusinessRules" />
<many-to-one name="BranchFrom" column="BranchFrom" class="Jas.SalesLeads.BusinessRules.Branch, Jas.SalesLeads.BusinessRules" />
<many-to-one name="InsertBy" column="InsertBy" class="Jas.SalesLeads.BusinessRules.User, Jas.SalesLeads.BusinessRules" />
<many-to-one name="UserInCharge" column="UserInCharge" class="Jas.SalesLeads.BusinessRules.User, Jas.SalesLeads.BusinessRules" />
<many-to-one name="CountryTo" column="CountryTo" class="Jas.SalesLeads.BusinessRules.AppCountry, Jas.SalesLeads.BusinessRules" />
<many-to-one name="CompanyTo" column="CompanyTo" class="Jas.SalesLeads.BusinessRules.Company, Jas.SalesLeads.BusinessRules" />
<many-to-one name="OfficeTo" column="OfficeTo" class="Jas.SalesLeads.BusinessRules.Office, Jas.SalesLeads.BusinessRules" />
<many-to-one name="RecipientGroup" column="RecipientGroup" class="Jas.SalesLeads.BusinessRules.RecipientGroup, Jas.SalesLeads.BusinessRules" />
<many-to-one name="Ratio" column="Ratio" class="Jas.SalesLeads.BusinessRules.ShipmentRatio, Jas.SalesLeads.BusinessRules" not-null="true" />
<many-to-one name="Frequency" column="Frequency" class="Jas.SalesLeads.BusinessRules.ShipmentFrequency, Jas.SalesLeads.BusinessRules" not-null="true" />

<bag name="SalesLeadRemarks" table="tbSalesLeadRemark" inverse="true" cascade="delete">
<key column="SalesLeadId" />
<one-to-many class="Jas.SalesLeads.BusinessRules.SalesLeadRemark, Jas.SalesLeads.BusinessRules"/>
</bag>
<bag name="SalesLeadHistoryItems" table="tbSalesLeadHistoryItems" inverse="true" cascade="delete">
<key column="SalesLeadId" />
<one-to-many class="Jas.SalesLeads.BusinessRules.SalesLeadHistoryItem, Jas.SalesLeads.BusinessRules"/>
</bag>

</class>
</hibernate-mapping>


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Jas.SalesLeads.BusinessRules.Area,Jas.SalesLeads.BusinessRules" table="tbArea">

<id name="AreaId" column="AreaId" type="String">
<generator class="assigned"/>
</id>
<timestamp column="Timestamp" name="Timestamp"/>
<property column="AreaName" type="String" name="AreaName" not-null="true"/>

<bag name="Branches" table="tbBranch" inverse="true">
<key column="AreaId" />
<one-to-many class="Jas.SalesLeads.BusinessRules.Branch, Jas.SalesLeads.BusinessRules"/>
</bag>
<bag name="UserRoleAreaManagers" table="tbRelAreaManagers">
<key column="AreaId" />
<many-to-many column="UserRoleId" class="Jas.SalesLeads.BusinessRules.UserRoles.IUserRole, Jas.SalesLeads.BusinessRules"/>
</bag>
<bag name="UserRoleSalesCoordinators" table="tbRelSalesCoordinators">
<key column="AreaId" />
<many-to-many column="UserRoleId" class="Jas.SalesLeads.BusinessRules.UserRoles.IUserRole, Jas.SalesLeads.BusinessRules"/>
</bag>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

[QueryException: could not resolve property:BranchFrom.Area of :Jas.SalesLeads.BusinessRules.SalesLeadItem]
Jas.SalesLeads.BusinessRules.Filters.SalesLeadItem_AreaManager.AddCriterion() in c:\intranet\salesleads\businessrules\filters\salesleaditem_areamanager.cs:51
Jas.SalesLeads.BusinessRules.Filters.RoleFilterCollection.ComposeCriteria(User obUser) in C:\Intranet\SalesLeads\BusinessRules\Filters\RoleFilterCollection.cs:67
Jas.SalesLeads.BusinessRules.SalesLeadItem.StandardFilters(User obUser, ICriteria obCriteria) in c:\intranet\salesleads\businessrules\salesleaditem.cs:841

[TargetInvocationException: Eccezione generata dalla destinazione di una chiamata.]
System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess) +0
System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean verifyAccess) +317
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +23
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +14
Jas.Com.BusinessFacade.HibernateCriteriaAdapter..ctor(IUser obUser, Boolean bnIsPaged, Type obType) in c:\intranet\common\businessfacade\hibernatecriteriaadapter.cs:52
Jas.Com.WebControls.JasObjectPager.Initialize(Type obType) in c:\intranet\common\webcontrols\jasobjectpager\jasobjectpager.cs:52
Jas.SalesLeads.WebUI.AspPages.SalesLeadsList.InitializeLists() in c:\intranet\salesleads\salesleads_webui\asppages\salesleadslist.aspx.cs:101
Jas.SalesLeads.WebUI.AspPages.SalesLeadsList.Page_Load(Object sender, EventArgs e) in c:\intranet\salesleads\salesleads_webui\asppages\salesleadslist.aspx.cs:70
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()



Name and version of the database you are using:
MSSQL Server 2000
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

NHibernate.QueryException: could not resolve property:BranchFrom.Area of :Jas.SalesLeads.BusinessRules.SalesLeadItem


-----------------

Basically when i try to create a Criterion tha links an object refenced inside my class i get an error . It looks like Hibernate when using Criterias does not understand that Area (Type Area) is a property of BranchForm (type Branch) the mapping is right since i used it for months ..i am just now switchuing from HQL to Criterias and finding this prolem

Expression.In("BranchFrom.Area", list);


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 11, 2006 7:33 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You can't use paths like this in criteria queries, use ICriteria.CreateCriteria or ICriteria.CreateAlias.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 11, 2006 12:11 pm 
Newbie

Joined: Mon Apr 10, 2006 8:45 am
Posts: 2
I have seen an example in a tutorial that was doing exactly what I was doing.

Plus this works:

Code:
obCriterion1 = Expression.Eq("UserInCharge.UserId", base.OwningUser.UserId);
obCriterion2 = Expression.Eq("InsertBy.UserId", base.RoleToCheck.OwningUser.UserId);


And it has a path, not a single object referene, as argument of the Eq() function.

The only difference is that UserId is a primitive type, while BranchFrom.Area is a UserType.


I have tried your solution using CreateCriteria:

Code:

((ICriteria)base._ParentCollection.Criteria).CreateCriteria("BranchFrom.Area", "UserArea");

obCriterion = Expression.In("UserArea", ((AreaManager)base.RoleToCheck).Areas);



this is what i get anyway

{"could not resolve property:BranchFrom.Area of :Jas.SalesLeads.BusinessRules.SalesLeadItem" }

it just would not recognize BranchFrom.Area as 2 separate entities.

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 2:27 am 
Newbie

Joined: Fri Mar 03, 2006 5:55 am
Posts: 7
If i'm not mistaken you should create alias for BranchFrom - say "BF", then alias for "BF.Area" say "UserArea" and only then apply your In expression


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