-->
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: many-to-any mapping - how does it work?
PostPosted: Fri Mar 17, 2006 1:56 am 
Newbie

Joined: Thu Feb 03, 2005 9:25 am
Posts: 4
Is there any chance of getting a complete example of how a many-to-any mapping works? I've been looking all day and just about have the documentation on the subject memorized and it seems to be a pretty elusive Hibernate/NHibernate feature. I am developing a system which maintains a good bit of meta-data about the objects being maintained. From this meta-data I am trying to navigate to the instances themselves using a polymorphic association...I think this is a good application of the many-to-any mapping.

Currently I am trying to map it using a Bag pointing to an IList in the object; however, the SQL generated by my mapping (below) tries to select from a table by that list's name...I've definately go something wrong.

Any examples of proper usage of a many-to-any would be very helpful.

Thanks,
Brad


Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 1.0.2

Mapping documents: Here is a snippet from the mapping:

<class name="Alipod.SystemObjects.SystemModule.TypeDefinition, SystemObjects" table="SystemModule_TypeDefinition">
<cache usage="read-write"/>
<id name="ObjectId" column="id" type="Int64" unsaved-value="0">
<generator class="identity"/>
</id>

<bag name="Instances" inverse="true" >
<cache usage="read-write"/>
<key column="TypeDefinition"/>
<many-to-any meta-type="String" id-type="Int64">
<meta-value value="Account" class="Alipod.SystemObjects.AccountingDomain.Account, SystemObjects"/>
<meta-value value="AccountingEntry" class="Alipod.SystemObjects.AccountingDomain.AccountingEntry, SystemObjects"/>
<column name="TypeName"/>
<column name="id"/>
</many-to-any>
</bag>
</class>


Code between sessionFactory.openSession() and session.close():
TypeDefinition = (TypeDefinition)Session.Load(TypeDefinition, id);



Full stack trace of any exception that occurs:
" at NHibernate.Collection.AbstractCollectionPersister.Initialize(Object key, ISessionImplementor session)\r\n at NHibernate.Impl.SessionImpl.InitializeCollection(PersistentCollection collection, Boolean writing)\r\n at NHibernate.Collection.PersistentCollection.ForceInitialization()\r\n at NHibernate.Impl.SessionImpl.InitializeNonLazyCollections()\r\n at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)\r\n at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object[] values, IType[] types, Object optionalObject, Object optionalID)\r\n at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, Object optionalIdentifier)\r\n at NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId)\r
\n at NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject)\r\n at NHibernate.Persister.EntityPersister.Load(Object id, Object optionalObject, LockMode lockMode, ISessionImplementor session)\r\n at NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted)\r\n at NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation)\r\n at NHibernate.Impl.SessionImpl.Load(Type clazz, Object id)\r\n at Alipod.SystemObjects.AbstractBusinessObjectFactory`1.getById(Int64 id) in D:\\Dev\\Alipod\\Code\\SystemObjects\\AbstractBusinessObjectFactory.cs:line 175"
Name and version of the database you are using:
SQL Server 2005

The generated SQL (show_sql=true):
exec sp_executesql N'SELECT instances0_.TypeDefinition as TypeDefi1___, instances0_.TypeName as TypeName__, instances0_.id as id__ FROM Instances instances0_
WHERE instances0_.TypeDefinition=@p0',N'@p0 bigint',@p0=1


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.