NHibernate could not get or update next value[SQL: ] 对象名 'hibernate_unique_key' 无效。

网友投稿 768 2022-10-16

NHibernate could not get or update next value[SQL: ] 对象名 'hibernate_unique_key' 无效。

NHibernate  could not get or update next value[SQL: ]  对象名 'hibernate_unique_key' 无效。

错误信息:

------------------------------------------------------NHibernate.Exceptions.GenericADOException: could not get or update next value[SQL: ] ---> System.Data.SqlClient.SqlException: 对象名 'hibernate_unique_key' 无效。 在 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) 在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) 在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) 在 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) 在 System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() 在 System.Data.SqlClient.SqlDataReader.get_MetaData() 在 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) 在 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest) 在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) 在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) 在 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) 在 System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) 在 System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() 在 NHibernate.Id.TableGenerator.DoWorkInCurrentTransaction(ISessionImplementor session, IDbConnection conn, IDbTransaction transaction) 在 NHibernate.Engine.TransactionHelper.Work.DoWork(IDbConnection connection, IDbTransaction transaction) --- 内部异常堆栈跟踪的结尾 --- 在 NHibernate.Engine.TransactionHelper.Work.DoWork(IDbConnection connection, IDbTransaction transaction) 在 NHibernate.Transaction.AdoNetTransactionFactory.ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, Boolean transacted) 在 NHibernate.Transaction.AdoNetWithDistributedTransactionFactory.ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, Boolean transacted) 在 NHibernate.Engine.Transaction.Isolater.DoIsolatedWork(IIsolatedWork work, ISessionImplementor session) 在 NHibernate.Engine.TransactionHelper.DoWorkInNewTransaction(ISessionImplementor session) 在 NHibernate.Id.TableGenerator.Generate(ISessionImplementor session, Object obj) 在 NHibernate.Id.TableHiLoGenerator.Generate(ISessionImplementor session, Object obj) 在 NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) 在 NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event) 在 NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event) 在 NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event) 在 NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event) 在 NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event) 在 NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event) 在 NHibernate.Impl.SessionImpl.Save(Object obj) 在 WindowsFormsApplication1.Form1.Form1_Load(Object sender, EventArgs e) 位置 C:\Users\JianKunKing\Desktop\NHibernate\NHibernate03\WindowsFormsApplication1\Form1.cs:行号 41

解决方法: I’ve genereated a schema for my (SQL 2005) db using SchemaExport, and it’s created a table

CREATE TABLE [dbo].[hibernate_unique_key]( [next_hi][int] NULL) ON [PRIMARY]

When I try to add an entity, I get the error:

------------------------------------------------------NHibernate.Id.IdentifierGenerationException: could not read a hi value - you need to populate the table: hibernate_unique_key 在 NHibernate.Id.TableGenerator.DoWorkInCurrentTransaction(ISessionImplementor session, IDbConnection conn, IDbTransaction transaction) 在 NHibernate.Engine.TransactionHelper.Work.DoWork(IDbConnection connection, IDbTransaction transaction) 在 NHibernate.Transaction.AdoNetTransactionFactory.ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, Boolean transacted) 在 NHibernate.Transaction.AdoNetWithDistributedTransactionFactory.ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, Boolean transacted) 在 NHibernate.Engine.Transaction.Isolater.DoIsolatedWork(IIsolatedWork work, ISessionImplementor session) 在 NHibernate.Engine.TransactionHelper.DoWorkInNewTransaction(ISessionImplementor session) 在 NHibernate.Id.TableGenerator.Generate(ISessionImplementor session, Object obj) 在 NHibernate.Id.TableHiLoGenerator.Generate(ISessionImplementor session, Object obj) 在 NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) 在 NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event) 在 NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event) 在 NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event) 在 NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event) 在 NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event) 在 NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event) 在 NHibernate.Impl.SessionImpl.Save(Object obj) 在 WindowsFormsApplication1.Form1.Form1_Load(Object sender, EventArgs e) 位置 C:\Users\JianKunKing\Desktop\NHibernate\NHibernate03\WindowsFormsApplication1\Form1.cs:行号 42

Solution: NHibernate expects to find a value that stores the current hi value in that table, ie it first runs something like:

current_hi =[SELECT max(next_hi) FROM

So all you need to do is seed that table with an initial number, ie:

INSERT INTO hibernate_unique_key(next_hi) VALUES (0)

参考文章: ​​​在部署OLAT到myeclipse,数据库配置正确的情况下,出现异常:Error with hilo in NHibernate - “could not read a hi value - you​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Netty分布式ByteBuf使用subPage级别内存分配剖析
下一篇:Cucumber - BDD 测试框架
相关文章

 发表评论

暂时没有评论,来抢沙发吧~