gpt4 book ai didi

hibernate - 臭名昭著的: Invalid index n for this SqlParameterCollection with Count=

转载 作者:行者123 更新时间:2023-12-03 14:30:22 25 4
gpt4 key购买 nike

这个异常(exception):

此 SqlParameterCollection 的索引 n 无效,Count=

通常指向重复的映射信息(参见 Stack Overflow + Google)。我很确定我没有。还有其他原因吗?

我似乎已经确定了问题所在。我介绍了这个:

[DocumentId]
public virtual int GI
{
get { return base.Id; }
protected set { base.Id = value; }
}

通过 lucene.net 使用搜索。这似乎干扰了FNH!我在这里有什么选择?

PS:
at System.Data.SqlClient.SqlParameterCollection.RangeCheck(Int32 index)
at System.Data.SqlClient.SqlParameterCollection.GetParameter(Int32 index)
at System.Data.Common.DbParameterCollection.System.Collections.IList.get_Item(Int32 index)
at NHibernate.Type.Int32Type.Set(IDbCommand rs, Object value, Int32 index)
at NHibernate.Type.NullableType.NullSafeSet(IDbCommand cmd, Object value, Int32 index)
at NHibernate.Type.NullableType.NullSafeSet(IDbCommand st, Object value, Int32 index, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Dehydrate(Object id, Object[] fields, Object rowId, Boolean[] includeProperty, Boolean[][] includeColumns, Int32 table, IDbCommand statement, ISessionImplementor session, Int32 index)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Object obj, ISessionImplementor session)
at NHibernate.Action.EntityInsertAction.Execute()
at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
at NHibernate.Engine.ActionQueue.ExecuteActions()
at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
at NHibernate.Impl.SessionImpl.Flush()
at SharpArch.Data.NHibernate.DbContext.CommitChanges()
at Updater1.Program.Main(String[] args) in C:\Users\bla\Documents\Visual Studio 2010\Projects\Bla\Updater1\Program.cs:line 97

PP:
public class MappedSequenceMap : IAutoMappingOverride<MappedSequence>
{
public void Override(AutoMapping<MappedSequence> mapping)
{
mapping.Id(x => x.Id, "GI").GeneratedBy.Assigned();

mapping.Map(x => x.Affiliation).Length(10000);
mapping.Map(x => x.Gene).Length(10000);
mapping.Map(x => x.OriginalIsolationCountry).Length(10000);
mapping.Map(x => x.OriginalAffiliation).Length(10000);
mapping.Map(x => x.PMIDs).Length(10000);
mapping.Map(x => x.Product).Length(10000);
mapping.Map(x => x.Fasta).Length(10000);
mapping.Map(x => x.Note).Length(10000);
mapping.Map(x => x.Strain).Length(10000);

mapping.HasManyToMany(x => x.PubmedPublications).Table("SequencesPubmedPublications");
}
}

最佳答案

答案是:-

a)您在同一类中映射了重复的属性

b) 如果您要公开外键并使用 <many-to-one ...,则有可能到映射文件中的相关实体。如果是这种情况,请添加 insert="false" and update="false"到外键属性并再次运行。

为了验证这一点,当您使用 fluent 和自动映射时,您需要查看 XML 映射。查看此 [链接][2] 并使用 ExportTo(..)方法。完成此操作后,请查看 XML看看你是否有任何重复的属性,甚至重复的映射文件。

在您的情况下,您有两个对列 GI 的引用:

<id name="Id" ...>
<column name="GI" />
<generator class="assigned" />
</id>

<property name="GI" ...>
<column name="GI" />
</property>

我认为你不能设置注释 [DocumentId]Id类属性。我认为您可能需要放弃此类的自动映射并通过 fluent 手动配置!

关于hibernate - 臭名昭著的: Invalid index n for this SqlParameterCollection with Count=,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10718228/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com