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: NHibernate.QueryException : could not resolve property
PostPosted: Tue Jul 17, 2007 5:09 pm 
Newbie

Joined: Tue Jul 17, 2007 4:04 pm
Posts: 3
Hi,

I'm trying to do a simple join query using LinqForNHibernate -> NHibernate -> MS SQL 2005. In LINQ, it looks like this:

var fileVersions =
(from fileVersion in linqContext.FileVersions
where fileVersion.File.FileName == fileName
select fileVersion).ToList<FileVersion>();

I.e., give me all the file versions of a file with a given file name. FileVersion and File are separate object and tables. A one-to-many map from FileVersion to File. See mapping files below.

I get the error:

NHibernate.QueryException : could not resolve property: File.FileName of: Autodesk.Collaboration.Platform.Data.Objects.FileVersion

See full stack trace below. I believe FileVersion.File.FileName is clearly "defined" by the map.

Interestingly, this works fine:

var fileVersions =
(from fileVersion in linqContext.FileVersions
where fileVersion.File.Id == fileId
select fileVersion).ToList<FileVersion>();

I.e., give me all the file versions of a file with a given id.

LinqForNhibernate uses Criteria. I've read that criteria based queries won't support the first query, but will support the second (http://forum.hibernate.org/viewtopic.php?t=952265). Is this true? The odd thing is, I have a sample test from the LinqForNHibernate test suite which appears to be very simialar (formally identical) to my first query (the one against fileName)....

Anyone have any ideas? I can certainly try to do this in "raw" hibernate code to get closer to the problem, but maybe it will be obvious to someone what I'm doing wrong here.

Thanks,
Hawkeye Parker


Hibernate version:
1.2

Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Autodesk.Collaboration.Platform.Data.Objects"
assembly="Autodesk.Collaboration.Platform">
<class name="Autodesk.Collaboration.Platform.Data.Objects.FileVersion" table="FileVersion" lazy="false">

<id name="Id" column="Id" type="int">
<generator class="Autodesk.Collaboration.Platform.Data.SequenceGenerator, Autodesk.Collaboration.Platform" />
</id>

<many-to-one name="File" class="Autodesk.Collaboration.Platform.Data.Objects.File, Autodesk.Collaboration.Platform" not-null="true" fetch="select">
<column name="FileId" not-null="true" />
</many-to-one>

<property name="VersionNumber" column="VersionNumber" type="long" not-null="true" />
<property name="FileSize" column="FileSize" type="long" not-null="true" />
<property name="UploadedOn" column="UploadedOn" type="DateTime" not-null="true" />

</class>
</hibernate-mapping>


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Autodesk.Collaboration.Platform.Data.Objects"
assembly="Autodesk.Collaboration.Platform">
<class name="Autodesk.Collaboration.Platform.Data.Objects.File" table="FileInfo" lazy="false">

<id name="Id" column="Id" type="int">
<generator class="Autodesk.Collaboration.Platform.Data.SequenceGenerator, Autodesk.Collaboration.Platform" />
</id>

<property name="FileName" column="FileName" type="string" not-null="true" />

<many-to-one name="Project" column="ProjectId"
class="Autodesk.Collaboration.Platform.Data.Objects.Project" cascade="save-update" not-null="true" />

<property name="ParentId" column="ParentId" type="int" not-null="true" />

<!--This is a computed property with the largest revision available on this file-->
<property name="LatestVersion" type="int" formula="(SELECT MAX(FV.VersionNumber) FROM FileVersion FV WHERE FV.FileId=Id)" not-null="true" />

</class>
</hibernate-mapping>

Full stack trace of any exception that occurs:
TestCase 'Autodesk.Collaboration.Test.UnitTests.Platform.FileManagement.FileApiTests.TestFileVersionTemp'
failed: NHibernate.QueryException : could not resolve property: File.FileName of: Autodesk.Collaboration.Platform.Data.Objects.FileVersion
at NHibernate.Persister.Entity.AbstractPropertyMapping.ThrowPropertyException(String propertyName)
at NHibernate.Persister.Entity.AbstractPropertyMapping.ToColumns(String alias, String propertyName)
at NHibernate.Persister.Entity.AbstractEntityPersister.ToColumns(String alias, String propertyName)
at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetColumns(String propertyName, ICriteria subcriteria)
at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetColumnsUsingProjection(ICriteria subcriteria, String propertyName)
at NHibernate.Expression.SimpleExpression.ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters)
at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetWhereCondition(IDictionary enabledFilters)
at NHibernate.Loader.Criteria.CriteriaJoinWalker..ctor(IOuterJoinLoadable persister, CriteriaQueryTranslator translator, ISessionFactoryImplementor factory, CriteriaImpl criteria, Type rootEntityName, IDictionary enabledFilters)
at NHibernate.Loader.Criteria.CriteriaLoader..ctor(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl rootCriteria, Type rootEntityName, IDictionary enabledFilters)
at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria, IList results)
at NHibernate.Impl.SessionImpl.Find[T](CriteriaImpl criteria)
at NHibernate.Impl.CriteriaImpl.List[T]()
D:\Develop\Collaboration\Main\Platform\Data\Linq\NHibernateLinqQuery.cs(972,0): at Autodesk.Collaboration.Platform.Data.Linq.NHibernateLinqQueryCollection`1.get_Result()
D:\Develop\Collaboration\Main\Platform\Data\Linq\NHibernateLinqQuery.cs(650,0): at Autodesk.Collaboration.Platform.Data.Linq.NHibernateLinqQueryCollection`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
D:\Develop\Collaboration\Main\Platform\FileManagement\FileApi.cs(367,0): at Autodesk.Collaboration.Platform.FileManagement.FileApi.TestGetName(String fileName)
D:\Develop\Collaboration\Main\Test\UnitTests\Platform\FileManagement\FileApiTests.cs(250,0): at Autodesk.Collaboration.Test.UnitTests.Platform.FileManagement.FileApiTests.TestFileVersionTemp()

Name and version of the database you are using:
MS SQL 2005 9.0.1399

The generated SQL (show_sql=true):
Not getting any SQL at profiler.

Debug level Hibernate log excerpt:

Not sure if all logging is turned on:

2007/07/17 13:52:50.216 Debug SEQ(00001589120163497630) TID(0000000A) LOC(NHibernate.Impl.SessionImpl.FlushEverything(:0) MSG(flushing session)
2007/07/17 13:52:50.216 Debug SEQ(00001589120164365200) TID(0000000A) LOC(NHibernate.Impl.SessionImpl.FlushEntities(:0) MSG(Flushing entities and processing referenced collections)
2007/07/17 13:52:50.216 Debug SEQ(00001589120165169370) TID(0000000A) LOC(NHibernate.Impl.SessionImpl.FlushCollections(:0) MSG(Processing unreferenced collections)
2007/07/17 13:52:50.216 Debug SEQ(00001589120165957070) TID(0000000A) LOC(NHibernate.Impl.SessionImpl.FlushCollections(:0) MSG(scheduling collection removes/(re)creates/updates)
2007/07/17 13:52:50.216 Debug SEQ(00001589120166736270) TID(0000000A) LOC(NHibernate.Impl.SessionImpl.FlushEverything(:0) MSG(Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects)
2007/07/17 13:52:50.216 Debug SEQ(00001589120167523790) TID(0000000A) LOC(NHibernate.Impl.SessionImpl.FlushEverything(:0) MSG(Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections)
2007/07/17 13:52:50.216 Debug SEQ(00001589120168298290) TID(0000000A) LOC(NHibernate.Impl.SessionImpl.Execute(:0) MSG(executing flush)
2007/07/17 13:52:50.216 Debug SEQ(00001589120169066480) TID(0000000A) LOC(NHibernate.Impl.SessionImpl.Execute(:0) MSG(registering flush begin)
2007/07/17 13:52:50.216 Debug SEQ(00001589120169858180) TID(0000000A) LOC(NHibernate.Impl.SessionImpl.Execute(:0) MSG(registering flush end)
2007/07/17 13:52:50.216 Debug SEQ(00001589120170729450) TID(0000000A) LOC(NHibernate.Impl.ConnectionManager.AggressiveRelease(:0) MSG(aggressively releasing database connection)
2007/07/17 13:52:50.216 Debug SEQ(00001589120171784960) TID(0000000A) LOC(NHibernate.Impl.SessionImpl.PostFlush(:0) MSG(post flush)
2007/07/17 13:52:50.216 Debug SEQ(00001589120172605680) TID(0000000A) LOC(NHibernate.Impl.SessionImpl.Close(:0) MSG(closing session)
2007/07/17 13:52:50.232 Debug SEQ(00001589120173413870) TID(0000000A) LOC(NHibernate.Impl.BatcherImpl.Dispose(:0) MSG(running BatcherImpl.Dispose(true))


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.