-->
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.  [ 2 posts ] 
Author Message
 Post subject: Need help with ordered set with autogenerated ordering
PostPosted: Mon May 22, 2006 11:04 pm 
Beginner
Beginner

Joined: Mon Nov 21, 2005 6:38 pm
Posts: 30
Location: New Zealand
Hibernate version:
NHibernate 1.0.1
Name and version of the database you are using:
SQLServer 2000

Hi, I am trying to implement a set with an order-by attribute

Code:
<set name="Components" order-by="ListIndex" inverse="false" lazy="false" cascade="save-update">
      <key column="ComponentsId" />
      <one-to-many class="Definition,EAF.Domain.Model" />
    </set>


and I want the ListIndex column in the table to be an identity column so that unique values would be generated by the database whenever a new object is inserted. However this gives me the following NH exception:

Quote:
2006-05-23 14:10:34,903 [3160] ERROR NHibernate.Util.ADOExceptionReporter [(null)] - Specified cast is not valid.
2006-05-23 14:10:34,903 [3160] ERROR NHibernate.ADOException [(null)] - Could not save object
System.InvalidCastException: Specified cast is not valid.
at NHibernate.Type.SetType.Wrap(ISessionImplementor session, Object collection)
at NHibernate.Impl.WrapVisitor.ProcessArrayOrNewCollection(Object collection, PersistentCollectionType collectionType)
at NHibernate.Impl.WrapVisitor.ProcessCollection(Object collection, PersistentCollectionType collectionType)
at NHibernate.Impl.AbstractVisitor.ProcessValue(Object value, IType type)
at NHibernate.Impl.WrapVisitor.ProcessValues(Object[] values, IType[] types)
at NHibernate.Impl.SessionImpl.DoSave(Object theObj, Key key, IClassPersister persister, Boolean replicate, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)
at NHibernate.Impl.SessionImpl.DoSave(Object obj, Object id, IClassPersister persister, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)
at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)


Does anyone know what I am doing wrong?
Thanks,
Dean.

BTW I cannot use a <list> with an index as I cannot guarantee that the index will be sequential (hence the atempt to use order-by).


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 3:01 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
How is declared the "Components" property in class? As ISet or as IList? For <set> mapping, You MUST use ISet.

If You want to use IList, the <bag> mapping should be good for You.

Gert

_________________
If a reply helps You, rate it!


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