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: SQL Query & return join Question
PostPosted: Mon Sep 08, 2008 5:50 pm 
Newbie

Joined: Thu Sep 04, 2008 12:44 pm
Posts: 10
Hello I could use some help. I am trying to load an idbag using a custom loader, and am having an issue with the syntax. The idbag has a Setting class which has two properties, a Value and a SettingDefinition.

SettingDefinition is a class which has some other properties. From what I can tell I should be using a load-collection for setting, and a return-join for the definition.

I am getting an error about the alias I am using in the return-join. Any help would be greatly appreciated

Hibernate version: 2.0.0 GA

Mapping documents:
Code:
      <idbag name="PersistedSettings" table="OrganizationSetting" generic="true" cascade="save-update" inverse="false" >
         <collection-id column="Id" type="int">
            <generator class="identity"/>
         </collection-id>
         
         <key  column="OrganizationId"  >
            <column not-null="false" name="OrganizationId" />
         </key>
         
         <composite-element class="xxx.Setting, Cutter">            
            <property column="SettingValue" name="Value"/>            
            <many-to-one class="xxx.SettingDefinition"  column="SettingId" name="Definition"/>               
         </composite-element>
         
         <loader query-ref="Organization_GetSettings"/>
      </idbag>



Code:
<sql-query name="Organization_GetSettings">

      <load-collection alias="s"  role="Organization.PersistedSettings">
         <return-property name="element" column="OrganizationId"/>
         <return-property name="element.id" column="OrganizationId"/>

      </load-collection>

      <return-join alias="sd"   property="Definition" ></return-join>
      SELECT {s}.Value as {s.Value}, {s}.Id as {s.Id},isnull({s}.OrganizationId,:Organizationid) as {s.OrganizationId},
      {sd}.SettingId as {sd.SettingId}, {sd}.SettingKey as {sd.Key}, {sd}.Scope as {sd.Scope},{sd}.DefaultValue as {sd.Default}
      FROM Setting {sd}
      LEFT JOIN OrganizationSetting {s}
      ON {sd}.SettingId={s}.SettingId
      WHERE ISNULL(OrganizationId,:OrganizationId)=:OrganizationId

   </sql-query>
</hibernate-mapping>


Full stack trace of any exception that occurs:
Quote:
Test method xxx.MembershipServiceTest.TestUserPersistanceBackingStore threw exception: NHibernate.MappingException: Role attribute for sql query return [alias=sd] not formatted correctly {owningAlias.propertyName}.
Quote:
NHibernate.Cfg.XmlHbmBinding.ResultSetMappingBinder.CreateJoinReturn(HbmReturnJoin returnJoinSchema)
NHibernate.Cfg.XmlHbmBinding.ResultSetMappingBinder.CreateQueryReturn(Object item, Int32 count)
NHibernate.Cfg.XmlHbmBinding.ResultSetMappingBinder.Create(String name, Object[] items)
b__0(IDictionary`2 )
NHibernate.Cfg.Configuration.SecondPassCompile()
NHibernate.Cfg.Configuration.BuildSessionFactory()
...
....
Name and version of the database you are using:MS SqlServer 2005


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2008 12:44 pm 
Newbie

Joined: Thu Sep 04, 2008 12:44 pm
Posts: 10
So after re-reading the documentation I've realized that one of my earlier approaches seems more correct. For the return-join the property should be s.Definition where s is my alias and Definition is the property name on s.

However when I've made this change I end up with the following very generic error:

Quote:
NHibernate.HibernateException: Errors in named queries: {Organization_GetSettings}.


Dug through the log files and I found:

Code:
NHibernate.MappingException: Unknown collection role: Organization.PersistedSettings
   at NHibernate.Impl.SessionFactoryImpl.GetCollectionPersister(String role)
   at NHibernate.Loader.Custom.Sql.SQLQueryReturnProcessor.AddCollection(String role, String alias, IDictionary propertyResults)
   at NHibernate.Loader.Custom.Sql.SQLQueryReturnProcessor.ProcessCollectionReturn(NativeSQLQueryCollectionReturn collectionReturn)
   at NHibernate.Loader.Custom.Sql.SQLQueryReturnProcessor.ProcessReturn(INativeSQLQueryReturn rtn)
   at NHibernate.Loader.Custom.Sql.SQLQueryReturnProcessor.Process()
   at NHibernate.Loader.Custom.Sql.SQLCustomQuery..ctor(INativeSQLQueryReturn[] queryReturns, String sqlQuery, ICollection`1 additionalQuerySpaces, ISessionFactoryImplementor factory)
   at NHibernate.Engine.Query.NativeSQLQueryPlan..ctor(NativeSQLQuerySpecification specification, ISessionFactoryImplementor factory)
   at NHibernate.Engine.Query.QueryPlanCache.GetNativeSQLQueryPlan(NativeSQLQuerySpecification spec)
   at NHibernate.Impl.SessionFactoryImpl.CheckNamedQueries()


So what is the role attribute in load-collection what should I have put there?

Thanks,

Josh


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2008 1:40 pm 
Newbie

Joined: Thu Sep 04, 2008 12:44 pm
Posts: 10
Moving right along now, sorry for all the posts...I figured my last problem was that the role needed to have a fully qualified domain name.

So now when we run I am getting a NullReferenceException from


Quote:
NHibernate.Loader.Custom.Sql.SQLQueryReturnProcessor.ProcessJoinReturn(NativeSQLQueryJoinReturn fetchReturn) in D:\NHibernate\src\src\NHibernate\Loader\Custom\Sql\SQLQueryReturnProcessor.cs: line 271
NHibernate.Loader.Custom.Sql.SQLQueryReturnProcessor.ProcessReturn(INativeSQLQueryReturn rtn) in D:\NHibernate\src\src\NHibernate\Loader\Custom\Sql\SQLQueryReturnProcessor.cs: line 169
NHibernate.Loader.Custom.Sql.SQLQueryReturnProcessor.Process() in D:\NHibernate\src\src\NHibernate\Loader\Custom\Sql\SQLQueryReturnProcessor.cs: line 127
NHibernate.Loader.Custom.Sql.SQLCustomQuery..ctor(INativeSQLQueryReturn[] queryReturns, String sqlQuery, ICollection`1 additionalQuerySpaces, ISessionFactoryImplementor factory) in D:\NHibernate\src\src\NHibernate\Loader\Custom\Sql\SQLCustomQuery.cs: line 52
NHibernate.Engine.Query.NativeSQLQueryPlan..ctor(NativeSQLQuerySpecification specification, ISessionFactoryImplementor factory) in D:\NHibernate\src\src\NHibernate\Engine\Query\NativeSQLQueryPlan.cs: line 29
NHibernate.Engine.Query.QueryPlanCache.GetNativeSQLQueryPlan(NativeSQLQuerySpecification spec) in D:\NHibernate\src\src\NHibernate\Engine\Query\QueryPlanCache.cs: line 112
NHibernate.Impl.SessionFactoryImpl.CheckNamedQueries() in D:\NHibernate\src\src\NHibernate\Impl\SessionFactoryImpl.cs: line 441
NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) in D:\NHibernate\src\src\NHibernate\Impl\SessionFactoryImpl.cs: line 365
NHibernate.Cfg.Configuration.BuildSessionFactory() in D:\NHibernate\src\src\NHibernate\Cfg\Configuration.cs: line 988


Looks like the following two lines of code are the culprits:

Code:
         ISqlLoadable ownerPersister = (ISqlLoadable) alias2Persister[ownerAlias];
         IType returnType = ownerPersister.GetPropertyType(fetchReturn.OwnerProperty);


I'm guessing that ownerPersister is null since if fetReturn was null we'd have an exception alot earlier. The log file snippet that I think is relevant is:

Quote:
2008-09-09 13:30:36,758 [Agent: adapter run thread for test 'TestUserPersistanceBackingStore' with id 'ef67e09a-5c80-47dd-9f7d-f8b74ea34e45'] DEBUG NHibernate.Impl.SessionFactoryImpl - Checking named SQL query: Organization_GetSettings
2008-09-09 13:30:36,758 [Agent: adapter run thread for test 'TestUserPersistanceBackingStore' with id 'ef67e09a-5c80-47dd-9f7d-f8b74ea34e45'] DEBUG NHibernate.Engine.Query.QueryPlanCache - unable to locate native-sql query plan in cache; generating (SELECT {s.*},{sd.*}
FROM Setting {sd}
LEFT JOIN OrganizationSetting {s}
ON {sd}.SettingId={s}.SettingId
WHERE ISNULL(OrganizationId,:OrganizationId)=:OrganizationId)
2008-09-09 13:30:36,774 [Agent: adapter run thread for test 'TestUserPersistanceBackingStore' with id 'ef67e09a-5c80-47dd-9f7d-f8b74ea34e45'] DEBUG NHibernate.Loader.Custom.Sql.SQLCustomQuery - starting processing of sql query [SELECT {s.*},{sd.*}
FROM Setting {sd}
LEFT JOIN OrganizationSetting {s}
ON {sd}.SettingId={s}.SettingId
WHERE ISNULL(OrganizationId,:OrganizationId)=:OrganizationId]
2008-09-09 13:30:36,774 [Agent: adapter run thread for test 'TestUserPersistanceBackingStore' with id 'ef67e09a-5c80-47dd-9f7d-f8b74ea34e45'] DEBUG NHibernate.Loader.Custom.Sql.SQLQueryReturnProcessor - mapping alias [s] to collection-suffix [0__]
2008-09-09 13:30:36,774 [Agent: adapter run thread for test 'TestUserPersistanceBackingStore' with id 'ef67e09a-5c80-47dd-9f7d-f8b74ea34e45'] DEBUG NHibernate.Loader.Custom.Sql.SQLQueryReturnProcessor - mapping alias [s] to collection-suffix [1__]


Back to trying to understand nHibernate, again any help or guidance would be greatly appreciated.


Top
 Profile  
 
 Post subject: load-collection and composite elements
PostPosted: Tue Sep 09, 2008 3:13 pm 
Newbie

Joined: Thu Sep 04, 2008 12:44 pm
Posts: 10
After digging through the code, I've found that there is an AddCollection method which populates the alias2Persister hash.

What I noticed is it only does this if we have a OneToMany relationship. This is leading me to belive that load-Collection is not supported when using a composite-element?

Is this correct?


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.